none
docmd.gotorecord which event ? RRS feed

Answers

  • Looks like you posted the same question here:

    GotoRecord question

    Try the bookmark code I posted at your other question.  I think bookmarks are more reliable than gotorecord if you want to bring up a specific record by ID.


    Miriam Bizup Access MVP


    • Edited by mbizup MVP Tuesday, July 26, 2016 9:44 AM
    • Marked as answer by tekoko10 Wednesday, July 27, 2016 6:46 AM
    Tuesday, July 26, 2016 9:44 AM
  • Are you trying to change SUBFORM records?

    A possible problem with the gotorecord method is that it depends on record order, which is not necessarily the same as your record ID/autonumber.  For example,

    Docmd.gotorecord,, acGoto, 5 will take you to the FIFTH record, which may or may not be the recordID you want.

    Try this code using bookmarks instead of GotoRecord (Im assuming FeestPagnr is a numeric record ID that exists in your subform's recordsource):

    Dim rs as dao.recordset set rs = me.recordsetclone rs.movefirst rs.FindFirst "Feestpagnr =" & NZ(ELookup("feestpagnr", "Gebruikers", "gebruiker = '" & me.Parent.User & "'"), -1) If rs.NoMatch = True then msgbox "record not found" Else me.bookmark = rs.bookmark end if

    set rs = nothing



    Miriam Bizup Access MVP



    • Edited by mbizup MVP Tuesday, July 26, 2016 9:15 AM Corrected the NoMatch logic
    • Marked as answer by tekoko10 Wednesday, July 27, 2016 6:46 AM
    Tuesday, July 26, 2016 9:02 AM

All replies

  • I have a form on a navigation form and on open I want to go to a specific record :

    DoCmd.GoToRecord acdataform, "myform" , acGoTo, nr

    but I get error 2015 , although I've put this code on the on-open event of the form ...

    Monday, July 25, 2016 2:27 AM
  • on which event can one perform a goto record ?

    onload ? onopen ? ???

    Hi tekoko,

    In the Open event the records are not yet assigned, so you can better use the Load event.

    Imb.

    Monday, July 25, 2016 9:44 AM
  • even in the unload event on a form, I get "form not open" when I try to perform gotorecord

    Monday, July 25, 2016 12:01 PM
  • even in the unload event on a form, I get "form not open" when I try to perform gotorecord

    Hi tekoko,

    It is not the Unload event, but the Load event that you can use, that is after assigning a RecordSource to the form.

    This can also be done explicitely in the Open event, by assigning a RecordSource to the form, but thiss not standard Access.

    Imb.

    Monday, July 25, 2016 12:28 PM
  • Try using the On Load event instead of the On Open event. On Open occurs before the records have been loaded, so there is nothing to go to yet.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, July 25, 2016 3:04 PM
  • I get the same error on the load event
    Monday, July 25, 2016 9:12 PM
  • Try using the On Load event of the form on the navigation form (I assume it is "myform"):

    Private Sub Form_Load()
        DoCmd.GoToRecord , , acGoTo, nr
    End Sub

    You'd have to make nr a global (public) variable.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, July 25, 2016 9:20 PM
  • sorry, I meant  the on - load event, wrong typing

    this is my code

     varx = ELookup("feestpagnr", "Gebruikers", "gebruiker= '" & Me.Parent.user & "'")
            If varx > 1 Then
            nr = varx
                DoCmd.GoToRecord , , acGoTo, nr
            End If
           

    I look up the number of the  record the user wants to see (same as he closed the form)

    I get error 2105 : you can't go to the specified record

    although the record exists

    Tuesday, July 26, 2016 6:43 AM
  • this is my code

     varx = ELookup("feestpagnr", "Gebruikers", "gebruiker= '" & Me.Parent.user & "'")
            If varx > 1 Then
            nr = varx
                DoCmd.GoToRecord , , acGoTo, nr
            End If

    I look up the number of the  record the user wants to see (same as he closed the form)

    I get error 2105 : you can't go to the specified record

    although the record exists

    Tuesday, July 26, 2016 6:44 AM
  • Are you trying to change SUBFORM records?

    A possible problem with the gotorecord method is that it depends on record order, which is not necessarily the same as your record ID/autonumber.  For example,

    Docmd.gotorecord,, acGoto, 5 will take you to the FIFTH record, which may or may not be the recordID you want.

    Try this code using bookmarks instead of GotoRecord (Im assuming FeestPagnr is a numeric record ID that exists in your subform's recordsource):

    Dim rs as dao.recordset set rs = me.recordsetclone rs.movefirst rs.FindFirst "Feestpagnr =" & NZ(ELookup("feestpagnr", "Gebruikers", "gebruiker = '" & me.Parent.User & "'"), -1) If rs.NoMatch = True then msgbox "record not found" Else me.bookmark = rs.bookmark end if

    set rs = nothing



    Miriam Bizup Access MVP



    • Edited by mbizup MVP Tuesday, July 26, 2016 9:15 AM Corrected the NoMatch logic
    • Marked as answer by tekoko10 Wednesday, July 27, 2016 6:46 AM
    Tuesday, July 26, 2016 9:02 AM
  • Looks like you posted the same question here:

    GotoRecord question

    Try the bookmark code I posted at your other question.  I think bookmarks are more reliable than gotorecord if you want to bring up a specific record by ID.


    Miriam Bizup Access MVP


    • Edited by mbizup MVP Tuesday, July 26, 2016 9:44 AM
    • Marked as answer by tekoko10 Wednesday, July 27, 2016 6:46 AM
    Tuesday, July 26, 2016 9:44 AM
  • I want the fifth record if nr is 5
    Tuesday, July 26, 2016 2:53 PM
  • feestpagnr is just the recordnumber , it is not an ID
    Tuesday, July 26, 2016 2:55 PM
  • Hi tekoko,

    To check whether this issue is related with the specific event or the code itself, I suggest you add a button with this code, and click the button to run it.

    If it did not work, it would be helpful if you could share us your varx value and sample data records, and then we could try to reproduce it.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, July 27, 2016 5:46 AM
  • changed my form so I could use your code , now it works ! many thanks !!
    Wednesday, July 27, 2016 6:47 AM
  • Glad to help.  Good luck with your project.

    Miriam Bizup Access MVP

    Wednesday, July 27, 2016 8:20 AM