Open form to specific record, but not filter to it (1 Viewer)

gojets1721

Registered User.
Local time
Today, 01:31
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:31
Joined
Oct 29, 2018
Messages
21,474
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.
 

June7

AWF VIP
Local time
Today, 00:31
Joined
Mar 9, 2014
Messages
5,474
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:

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:31
Joined
May 21, 2018
Messages
8,529
Code:
DoCmd.OpenForm "frmDetails
Forms("frmDetails").recordset.findfirst "[ComplaintNumber] =" & Nz(Me.[ComplaintNumber], 0)
 
Last edited:

gojets1721

Registered User.
Local time
Today, 01:31
Joined
Jun 11, 2019
Messages
430
Code:
DoCmd.OpenForm "frmDetails
Forms("frmDetails").recordset.findfirst "[ComplaintNumber] =" & Nz(Me.[ComplaintNumber], 0)
This worked! Thanks so much
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:31
Joined
Feb 19, 2013
Messages
16,616
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

Top Bottom