Results 1 to 12 of 12
  1. #1
    stephenaa5 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    72

    Opening form to correct record. Bookmark?

    I have a form [ScopeDTL], which sits on a query, the PK is ScopeID, which is a text field. This form will not allow the data to be edited. A button on said form opens a second form [ScopeDTLeditable], which as you can guess allows the data to be edited. This form is opened to the correct ScopeID. Once the edits are made, the form is closed. Since ScopeDTL was left open behind, the correct ScopeID is shown, however, with the old data. Pressing "refresh" shoots you back to the first ScopeID, which may be hundreds away.

    I am looking to close ScopeDTLeditable, requery, and then have ScopeDTL display the ScopeID from which I left. I have gotten help on the following code, but it still doesn't work.

    Any help would be appreciated.

    Stephen.
    ------------code-------------

    Private Sub Command156_Click()
    Private Sub Form_Close()
    Dim strScopeID As String
    strScopeID = Nz(Me.ScopeID, "")
    If strScopeID <> "" Then
    Forms![ScopeDTL editable].Requery
    Dim rst As Recordset
    Set rst = Forms![ScopeDTL editable].RecordsetClone
    rst.FindFirst "[ScopeID] = " & "'" & strScopeID & "'"
    If Not rst.NoMatch Then Forms![ScopeDTL editable].Bookmark= rst.Bookmark


    rst.Close
    End If
    End Sub
    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This link may help a bit.

  3. #3
    stephenaa5 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    72
    Thanks! I'll check it out.

  4. #4
    stephenaa5 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    72
    The problem I'm having is that my situation is a form over a query, not a form over a table. Any ideas?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    As I see it, your problem is returning to the same record after a requery which is the same whether using a query or a table.

  6. #6
    stephenaa5 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    72
    Actually, I was able to make his example work on the query too. But my new problem is that the Primary Key is not an autonumber. It's a string. When I try to manipulate his example to set as string, and then choose EmpFname, it fails.

    Thoughts?

    Thanks!

    STephen.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Strings require quotes:
    rs.FindFirst "EmpID = '" & lngBookmark & "'"

  8. #8
    stephenaa5 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    72
    I'm sorely missing something simple...


    Private Sub cmdRequery_Click()
    Dim rs As Object
    Dim lngBookmark As String

    On Error GoTo Err_cmdRequery_Click
    'set a variable to the current record
    lngBookmark = Me.EmpFName
    'requery the form
    Me.Requery
    'bring us back to the original record
    Set rs = Me.RecordsetClone
    rs.FindFirst "EmpID = '" & lngBookmark & "'"
    Me.Bookmark = rs.Bookmark
    Exit_cmdRequery_Click:
    Set rs = Nothing
    Exit Sub
    Err_cmdRequery_Click:
    MsgBox Err.Description
    Resume Exit_cmdRequery_Click
    End Sub

  9. #9
    stephenaa5 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    72
    Nevermind. I got stupid. Figured it out. Thanks!

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That's great! What was your final code? Do you want to follow the link in my sig and mark this thread as Solved?

  11. #11
    stephenaa5 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    72
    Here is what worked.
    Thanks again.


    Private Sub cmdRequery_Click()
    Dim rs As Object
    Dim lngBookmark As String

    On Error GoTo Err_cmdRequery_Click
    'set a variable to the current record
    lngBookmark = Me.EmpFName
    'requery the form
    Me.Requery
    'bring us back to the original record
    Set rs = Me.RecordsetClone
    rs.FindFirst "EmpFname = '" & lngBookmark & "'"
    Me.Bookmark = rs.Bookmark
    Exit_cmdRequery_Click:
    Set rs = Nothing
    Exit Sub
    Err_cmdRequery_Click:
    MsgBox Err.Description
    Resume Exit_cmdRequery_Click
    End Sub

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I made a couple of changes and used the code tags, the # tool.
    Code:
    Private Sub cmdRequery_Click()
       Dim rs As DAO.Recordset
       Dim strBookmark As String
       On Error GoTo Err_cmdRequery_Click
       'set a variable to the current record
       strBookmark = Me.EmpFName
       'requery the form
       Me.Requery
       'bring us back to the original record
       Set rs = Me.RecordsetClone
       rs.FindFirst "EmpFname = '" & strBookmark & "'"
       If Not rs.NoMatch Then
          Me.Bookmark = rs.Bookmark
       Else
          MsgBox "Could not locate [" & strBookmark & "]", vbOKOnly + vbCritical
       End If
       
    Exit_cmdRequery_Click:
       Set rs = Nothing
       Exit Sub
       
    Err_cmdRequery_Click:
       MsgBox Err.Description
       Resume Exit_cmdRequery_Click
       
    End Sub

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

Similar Threads

  1. Bookmark a record in a Form?
    By westcoastbmx in forum Forms
    Replies: 3
    Last Post: 10-29-2009, 03:13 PM
  2. Replies: 4
    Last Post: 07-22-2009, 02:33 PM
  3. Trouble viewing correct data
    By KevinH in forum Access
    Replies: 11
    Last Post: 07-06-2009, 07:16 PM
  4. not correct running total in group
    By cmk in forum Reports
    Replies: 1
    Last Post: 12-06-2006, 05:56 PM
  5. Replies: 2
    Last Post: 12-01-2006, 07:23 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