Results 1 to 11 of 11

Thread: GoToRecord help

  1. #1
    Join Date
    Aug 2006
    Posts
    10

    Unanswered: GoToRecord help

    I have the following code but it does not work correctly.

    DoCmd.GoToRecord acDataForm, "frm_Contact", acGoTo, Me.ContactID

    When the code executes it does not bring me to the correct record. If Me.ContactID is 15 it brings me to the 15th record not ContactID 15 which are different due to deletions. Is there any way to get it to the correct record?

    Thanks.

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by boss8246
    I have the following code but it does not work correctly.

    DoCmd.GoToRecord acDataForm, "frm_Contact", acGoTo, Me.ContactID

    When the code executes it does not bring me to the correct record. If Me.ContactID is 15 it brings me to the 15th record not ContactID 15 which are different due to deletions. Is there any way to get it to the correct record?

    Thanks.
    It's doing what it is designed to do ... Goto the Xth record in the list ... What do you want it to do? If you're looking for the ContactID equaling 15 then you'll need to use a different methodology ... FindFirst and RecordClones come to mind ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Aug 2006
    Posts
    10
    I am trying to get it to Find or GoTo a record that is selected from a ComboBox. But, because some records have been deleted it isn't working correctly now. The combo box is basically a lookup box or a search engine.

    I am not fimilar with FindFirst or RecordClones. I will see about looking them up.

    Thanks.

  4. #4
    Join Date
    Aug 2006
    Posts
    10
    M Owen,

    I have looked over the FindFirst and RecordClones and I can't seem to figure out how this code would or does work. If you could maybe help me with an example.

    Thanks.

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Try this:

    Code:
    Private Sub YourComboboxName_AfterUpdate()
    
    Set rs = Me.Recordset.Clone
            rs.findfirst "[YourIDFieldName] = '" & Me![YourComboboxName] & "'"
            Me.Bookmark = rs.Bookmark
    End Sub
    The single and double quotes can be kind of hard to distinguish; best way is to copy and paste, then replace YourComboboxName and YourIDFieldName with your actual names. Also remember to delete the existing AfterUpdate sub for your combobox, if that's what your were using for your original code here.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    Join Date
    Aug 2006
    Posts
    10
    Missinglinq,

    Your code works if I put the combo box on my main form, but I am trying to use a separate form that pops up when you click on a command button on the main form to do the record lookup. Then on the afterupdate on the second form's combo box, it would find the record in the main form and then close the second form.

    I think this makes sense.

    Thanks.

  7. #7
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by boss8246
    Missinglinq,

    Your code works if I put the combo box on my main form, but I am trying to use a separate form that pops up when you click on a command button on the main form to do the record lookup. Then on the afterupdate on the second form's combo box, it would find the record in the main form and then close the second form.

    I think this makes sense.

    Thanks.
    Change Me to your Form's name ... Miss' code should still work ...
    Back to Access ... ADO is not the way to go for speed ...

  8. #8
    Join Date
    Aug 2006
    Posts
    10
    M Owen,

    Well I have tried that and I still can't seem to get it to work. Do I need to include the primary key field name? Or is there something else I could be missing?

    Thanks.

  9. #9
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Exactly why do you want to go to the trouble of opening a second form simply to hold a combobox? If you're running out of room on your form, keep your command button and place the combobox on your main form. In the Form_Load sub set the combobox's Visible Property to False. In the Click sub of your command button, set the Visible Property to True. Then, in the After_Update sub code, after the line Me.Bookmark = rs.Bookmark do two things:

    1) Set the focus to any other control except the combobox
    2) Set the Visible Property of the combobox back to False
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  10. #10
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    So:

    Set Forms![WhateverYourFormNameIs].rs = Forms![WhateverYourFormNameIs].Recordset.Clone
    Forms![WhateverYourFormNameIs].findfirst "[YourIDFieldName] = '" & YourComboboxName & "'"
    Forms![WhateverYourFormNameIs].Bookmark = Forms![WhateverYourFormNameIs].rs.Bookmark

    Doesn't work? Did you do this?
    Back to Access ... ADO is not the way to go for speed ...

  11. #11
    Join Date
    Aug 2006
    Posts
    10
    Missinglinq & M Owen,

    The reason for the second form is due to a lack of space on my main form. I also have a dialog question when you open the database which opens the second form if NO is the answer to the question. So I would like to get the second form to work if I could.

    I am a little confused on M Owen's reply. Which of the "WhateverYourFormNameIs" would be the main form and which on would be the second form.

    Please bear with me. I am really new at creating databases, as for this is my first one.

    Thanks.

Posting Permissions

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