Open form to specific record, but not filter to it

gojets1721

Registered User.
Local time
Today, 02:55
Joined
Jun 11, 2019
Messages
430
I have a tabular form which lists a bunch of customer complaints. For each record, there's an 'open' button to view that specific record in a more detailed form. The below code for the open button works to pull up that record in the separate form, but it filters down to that exact record. Ideally, I would want to still be able to bounce around from record to record in the detailed form after it is pulled up. Any suggestions?

Code:
Private Sub txtOpen_Click()
On Error GoTo txtOpen_Click_Err

    DoCmd.OpenForm "frmDetails", , , "[ComplaintNumber] =" & Nz(Me.[ComplaintNumber], 0) & ""
    DoCmd.Close acForm, "frmComplaintList"

txtOpen_Click_Exit:
    Exit Sub

txtOpen_Click_Err:

    MsgBox "Error #" & Err.Number & " - " & Err.Description, , "Error"
    
    Resume txtOpen_Click_Exit

End Sub
 
One approach is to pass the ComplaintNumber in the OpenArgs argument of the OpenForm method and then process it in the Load event of the other form to navigate to that record using a recordset and the bookmark property.
 
A common approach is to use RecordsetClone and Bookmark to locate record. Review https://docs.microsoft.com/en-us/office/vba/api/Access.Form.RecordsetClone

And don't even need to declare recordset variable. Instead of the WHERE CONDITION argument, pass criteria with OpenArgs.
Code:
    With Me.RecordsetClone
        .FindFirst "LabNum='" & Me.OpenArgs & "'"
        Me.Bookmark = .Bookmark
    End With
 
Last edited:
Code:
DoCmd.OpenForm "frmDetails
Forms("frmDetails").recordset.findfirst "[ComplaintNumber] =" & Nz(Me.[ComplaintNumber], 0)
 
Last edited:
Just be aware the where parameter of openform is a filter, not a criteria. Simply remove the filter to see all the records
 

Users who are viewing this thread

Back
Top Bottom