Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Posts
    157

    Unanswered: Goto Record based on auto ID in a seperate form

    Goto Record based on auto ID in a seperate form.

    Hi there I have two forms called:
    eEmployer1HODetails
    eEmployer2SiteDetailsSearch

    The eEmployer2SiteDetailsSearch is a continuous form which displays specific details about each site in the table.

    The eEmployer2SiteDetailsSearch form is opened by an on click button event. The button is located on the eEmployer1HODetails form (which remains open whilst the eEmployer2SiteDetailsSearch form is open).


    Both Forms have fields which are called Company ID (referring to the same sort of information).
    eEmployer1HODetails has an autoID (company ID)
    eEmployer2SiteDetailsSearch is a stored ID (company ID)


    As a test a created an unbound field on the eEmployer2SiteDetailsSearch to test if the following code could capture the ID value after I click on one of the forms (in the continuous form listing) and it works.

    Private Sub Form_Current()
    Me.ID = Me.CompanyID 'Unbound field
    End Sub

    My next test was to see if I could get the record in the underlying form (eEmployer1HODetails) to be displayed based on the ID of the form which was clicked on.
    Private Sub Form_Current()
    Me.ID = Me.CompanyID 'Unbound field
    DoCmd.GoToRecord acForm, "eEmployer1HODetails", acGoTo, Me.ID
    End Sub

    This works in that it goes to the record number (on the record selector) with the same ID value.

    But it is not what I am actually trying to achieve. What I am trying to do is to get it to goto the same CompanyID as that chosen in the eEmployer2SiteDetailsSearch ID field.

    I hope I have explained myself clearly.

    Can anyone help me with this?

    Thanks heaps.
    Last edited by Karen Day; 11-09-09 at 03:46. Reason: correct spelling

  2. #2
    Join Date
    May 2002
    Posts
    157
    I have worked out the answer thanks to a post by PKStormy at http://www.dbforums.com/microsoft-ac...d-subform.html.

    Private Sub Form_Current()

    Dim SearchID As Variant

    SearchID = Forms!usysbeEmployer2SiteDetailsF!CompanyID

    Forms!eEmployer1HODetails.SetFocus 'Forms!MainFormName.SetFocus
    'Forms!MainFormName!SubFormName.setfocus (if using a subform)

    Forms!eEmployer1HODetails!CompanyID.SetFocus 'Forms!MainFormName!SubFormName!MyIDField.setfocus
    '(Note: MyIDField must be Visible and Enabled (but can be locked) on subform! - shrink box size on subform if you don't want to show this field.)

    DoCmd.FindRecord SearchID
    'Forms!eEmployer1HODetails![Active/Inactive].SetFocus 'Forms!MainFormName!SubFormName!SomeOtherField.set focus

    End Sub
    Last edited by Karen Day; 11-09-09 at 10:16. Reason: make info clearer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •