Results 1 to 8 of 8
  1. #1
    devcon is offline Novice
    Windows 7 Access 2007
    Join Date
    Jan 2010
    Posts
    24

    VBA Return to the selected record


    Good day,
    Please give me your suggestion.
    I have a form ‘Orders’ (Orders.jpeg) and if I double click of the ‘Order Code’ = (ID Vessel) open a second form ‘Form Record’ (Form Record.jpeg) that I can change the status etc.
    Now when I close the form ‘Form Record’ I need to return back to the ‘Orders’ form and the cursor to remain to the selected previous ‘Order Code’ not to the last one as actually.
    In the close form of the ‘Form Record’ the VBA is:

    Code:
    Private Sub Form_Close()
    Forms!Orders.Requery
    DoCmd.GoToRecord , , acLast
    End Sub
    Thank you.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,126
    One way that could be adapted to point to a different form:

    http://www.baldyweb.com/Requery.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    devcon is offline Novice
    Windows 7 Access 2007
    Join Date
    Jan 2010
    Posts
    24
    Quote Originally Posted by pbaldy View Post
    One way that could be adapted to point to a different form:

    http://www.baldyweb.com/Requery.htm

    Thank you Paul for your guidance, I will try.
    Have a nice day.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,126
    No problem; post back if you get stuck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    devcon is offline Novice
    Windows 7 Access 2007
    Join Date
    Jan 2010
    Posts
    24
    Quote Originally Posted by pbaldy View Post
    No problem; post back if you get stuck.
    Dear Paul,
    I am unable to return back to the selected record.
    Probably I am wrong on the code

    Code:
    Private Sub Form_Close()
    
    Dim rs As Object
    Dim lngBookmark As Long
    
    'set a variable to the current record
    lngBookmark = Me.[Order Code]
    'requery the form
    Me.Requery
    
    
    'bring us back to the original record
    Set rs = Me.RecordsetClone
    rs.FindFirst "[Order Code] = " & lngBookmark
    Me.Bookmark = rs.Bookmark
    
    Set rs = Nothing
    
    'Private Sub Form_Close()
    'Forms!Orders.Requery
    'DoCmd.GoToRecord , , acLast
    
    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,126
    You haven't said what goes wrong. Based on your original question, I'd expect all the Me references to point to the other form. You're basically doing the same as this:

    https://www.accessforums.net/access/...orm-22035.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    devcon is offline Novice
    Windows 7 Access 2007
    Join Date
    Jan 2010
    Posts
    24
    Quote Originally Posted by pbaldy View Post
    You haven't said what goes wrong. Based on your original question, I'd expect all the Me references to point to the other form. You're basically doing the same as this:

    https://www.accessforums.net/access/...orm-22035.html
    Thank you Paul.
    Now work perfectly.
    Have a nice day.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,126
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-13-2012, 08:14 AM
  2. Go to selected record
    By Newbie11 in forum Forms
    Replies: 4
    Last Post: 01-07-2012, 04:29 AM
  3. How to Print Selected Record
    By indranx in forum Reports
    Replies: 2
    Last Post: 05-31-2011, 09:54 PM
  4. Copying selected fields to a new record
    By Lyle Bitikofer in forum Forms
    Replies: 0
    Last Post: 12-13-2009, 04:01 PM
  5. Loading the form with selected record
    By emilylu3 in forum Access
    Replies: 1
    Last Post: 12-09-2005, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums