Emil
Emil

Reputation: 11

Custom navigation fails upon opening an individual record in Microsoft Access project

I'm having issues with my Microsoft Access project.

The project comprises of two forms called, InfoForm and SearchBox.

InfoForm form

The InfoForm form is the primary-form, and has the following:

SearchBox form

The SearchBox form is used to browse and open individual records, and has the following:

Individual records

The individual records open into the InfoForm form.

I use this code on the Open' button of theSearchBox` form, as follows:

Private Sub Command1_Click()

Dim strLN As String
strLN = Me.SearchResults.Column(0)

Dim strGN As String
strGN = Me.SearchResults.Column(1)

Dim strMN As String
strMN = Me.SearchResults.Column(2)

DoCmd.OpenForm "InfoForm", acNormal, , _
              "[Last Name] = '" & strLN & "' And " & _
              "[Given Name] = '" & strGN & "' And " & _
              "[Middle Name] = '" & strMN & "'"

DoCmd.Close acForm, "SearchBox"

End Sub

This code works perfectly when the InfoForm form is first opened, right up until an individual record is opened.

At this point, the navigation buttons "Next" and "Prev" on the 'InfoForm' form stop working.

Please help. Thank you.

Upvotes: 1

Views: 40

Answers (1)

June7
June7

Reputation: 21370

As @Andre noted, if the form is filtered to a single record then there are no succeeding or previous records to navigate to. Does your filter criteria result in a single record dataset?

An alternative is to open the form unfiltered (or with a filter that returns a restricted dataset but will usually still have multiple records) and 'go to' the desired record, then there will be succeeding and preceding records to navigate. Example from my code:

To open form: DoCmd.OpenForm "Samples", , , , , acDialog, strLabNum

Then code behind the opened form:

Private Sub Form_Open(Cancel As Integer)
Me.RecordsetClone.FindFirst "LabNum='" & Me.OpenArgs & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

Upvotes: 1

Related Questions