How to move the record counter in a form by selecting the related record in a listbox

usr_X

Registered User.
Local time
Today, 12:31
Joined
Jun 9, 2009
Messages
26
I have a form with a listbox displaying data from a table. I want to move the record counter in the form when the related record in the listbox is selected. Help is appreciated (as I experiment on this problem). Sincerely, Usr_X
 
Presuming the form is bound to a table, if you use the combo or list box wizard, choosing the third option, "Find a record...", the wizard will build the code for you.
 
Paul, thank you. I went ahead and got it to work using VBA (I have a *little* experience with VBA in Excel). Below is my solution. However, I have this question: Is the OnCurrent event at the form level the only way to get access to changes in the navigation buttons at the bottom of a form? Thanks again, Usr_X

*****

To reiterate what I was trying to do: Based on the selection in a listbox to update the navigation buttons at the bottom of the form and to get the navigation buttons to select the related record in the listbox. I used the following code:

Private Sub Form_Current()
Dim lstB As ListBox
Dim offsetdx As Integer

Set lstB = List0

If Me.NewRecord = True Then
DoCmd.GoToRecord , , acGoTo, Me.CurrentRecord - 1
End If

If lstB.ColumnHeads = False Then
offsetdx = 1
End If

If List0.ListIndex = -1 Then
Exit Sub
End If

If List0.ListIndex + offsetdx < Me.CurrentRecord Then
List0.Selected(List0.ListIndex + offsetdx) = False
End If

List0.Selected(Me.CurrentRecord - offsetdx) = True

'Me.SetFocus
Command14.SetFocus
'EmployeeNo.SetFocus

End Sub


Private Sub List0_AfterUpdate()

Dim rdx As Integer

rdx = List0.ListIndex + 1

DoCmd.GoToRecord , , acGoTo, rdx

End Sub
 
Last edited:
The wizard would have created code using a bookmark, but GoToRecord should work fine. The current event fires when the user changes records by any means, so it would be the appropriate event for your purposes, it sounds like.
 

Users who are viewing this thread

Back
Top Bottom