I have a combo box that gets values from a table. A user selects a value and clicks btnSave. How do I get the combo box to automatically select the next value? I would like it to be in the Click event of the Save button, but am not sure of the code.
Thanks for the quick reply, but alas, the code doesn't work (Access says the object doesn't support the property RTE '438'). At first I thought it was the fact that it was a combo box, but the problem persisted even after changing it to a list box.
Which property didn't it like? The Selected property is available only with a list box and only if it is not multiselect. For a combo box, just set the value of the box to the data in the next row like this:
Dim intRow As Integer
intRow = Me!YourComboBox.ListIndex
If intRow = Me!YourComboBox.ListCount - 1 Then
Me!YourComboBox.Value = Me!YourComboBox.Column(0, intRow - 1)
Else
Me!YourComboBox.Value = Me!YourComboBox.Column(0, intRow + 1)
End If
OK, I think I'm on track...I moved it from the button click and placed the code in the form after_update event. BUT...it says I may be at the end of a recordset (RTE 2105). What could be causing this?
Thanks for your patience with a dunderhead such as I...
The after update event is probably the wrong event because after the update the selection is gone. Try creating the intRow as a form level variable (in general declarations) then in the button click you set the variable the listindex and in the form load procedure set the variable to -1, finally, in the form current event use this code:
If intRow <> -1 Then
If intRow = Me!YourComboBox.ListCount - 1 Then
Me!YourComboBox.Value = Me!YourComboBox.Column(0, intRow - 1)
Else
Me!YourComboBox.Value = Me!YourComboBox.Column(0, intRow + 1)
End If
End IF
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.