lehi52
asked on
Next record button based on combo box
I am putting together a database form. I have a next record button. Right now the next record button goes to the next record from a table. But, I need the next record button to be based on the records shown in the right combo box.
At the top of the contact form. There are three combo boxes. I need the next record button to go to the next record of the records in the third right combo box.
See attached sample database.
1.accdb
At the top of the contact form. There are three combo boxes. I need the next record button to go to the next record of the records in the third right combo box.
See attached sample database.
1.accdb
ASKER
I get an error when I change the name in the code to the name of the combo box. This code refers to the "display" combo box. I am sure I did something wrong. I posted the code into the VBA code. Does the code need to be put into a specific event procedure to work?
display.SetFocus
If display.ListIndex <> display.ListCount - 1 Then
display.ListIndex = display.ListIndex + 1
Else
display.ListIndex = 0
End If
End Sub
------------------------------------------------------------
display.SetFocus
If display.ListIndex <> 0 Then
display.ListIndex = display.ListIndex - 1
Else
display.ListIndex = display.ListCount - 1
End If
End Sub
Where did you put this code ?
Private Sub Command51_Click()
Me.display.SetFocus
If Me.display.ListIndex <> Me.display.ListCount - 1 Then
Me.display.ListIndex = Me.display.ListIndex + 1
Else
Me.display.ListIndex = 0
End If
End Sub
Private Sub Command52_Click()
Me.display.SetFocus
If Me.display.ListIndex <> 0 Then
Me.display.ListIndex = Me.display.ListIndex - 1
Else
Me.display.ListIndex = display.ListCount - 1
End If
End Sub
ASKER
I just put it into the VBA code. no where specifically. I just added it into there. It did not work with those changes.
ASKER
It does work but it spits out an error. Run-Time Error '7777' You've used the List Index property incorrectly.
It goes to the next record and cycles through only those names, but the issue is after I click next each time the error pops up.
It goes to the next record and cycles through only those names, but the issue is after I click next each time the error pops up.
please upload your sample
ASKER
Here you go.
2.accdb
2.accdb
Go to the VBA (Press Alt+F11 from main application), then select debug / compile database.
when you will get an error comment that line, and compile again.
then test the code again.
when you will get an error comment that line, and compile again.
then test the code again.
ASKER
Now it cycles through, but it only changes the name in the combo box, and does not change the entire record displayed on the form.
add after the code display_AfterUpdate
Private Sub Command51_Click()
Me.display.SetFocus
If Me.display.ListIndex <> Me.display.ListCount - 1 Then
Me.display.ListIndex = Me.display.ListIndex + 1
Else
Me.display.ListIndex = 0
End If
display_AfterUpdate
End Sub
ASKER
Gives an error again after adding that. Same error as before.
3.accdb
3.accdb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just to let you know, you should compact your database regularly, the file you uploaded is 4.9MB and the file i uploaded is 1.5MB.
http://office.microsoft.com/en-us/access-help/compact-and-repair-an-access-file-HP005187449.aspx
http://office.microsoft.com/en-us/access-help/compact-and-repair-an-access-file-HP005187449.aspx
ASKER
Great solution. Thank you.
to go next
Open in new window
and to go backOpen in new window