3
votes

I have a form with ID numbers, and buttons that are supposed to open up another form with the relating record. In addition to that specific record being shown, i need all of the records to be opened because my form needs to have working Next and Previous buttons. I've been trying to for a couple days now, and I haven't been able to make opening all records and showing a specific one work at the same time. So here I've started over using the wizard to open all records. How should I fix it so that it shows the record clicked on?

Private Sub Command74_Click()

On Error GoTo Err_Go_to_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Contracts"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Go_to_Click:
    Exit Sub

Err_Go_to_Click:
    MsgBox Err.Description
    Resume Exit_Go_to_Click


End Sub

Thanks in advance!

1

1 Answers

1
votes

You need to navigate to the correct record after opening the form. I don't see the code to fill the strLinkCriteria so I supplied some dummy data in my example.

Private Sub Command74_Click()

On Error GoTo Err_Go_to_Click

Dim stDocName As String
Dim stLinkCriteria As String

stLinkCriteria = "ContactID = '" & Me.ContactID & "'"
stDocName = "Contracts"
'Open the form with no filter
DoCmd.OpenForm stDocName
'Go to the specified record
Forms(stDocName).Recordset.FindFirst stLinkCriteria

Exit_Go_to_Click:
    Exit Sub

Err_Go_to_Click:
    MsgBox Err.Description
    Resume Exit_Go_to_Click


End Sub