Hello,
I am trying to have 2 Command buttons to go to previous and next record based off an unbound combo box selections. I currently have the next command button code via VBA but I don't know how to do the opposite for a previous button. This is the code I am using for a next record:
And then for the Command button:
Anybody know how I could edit this code to do the opposite and go to previous record?
Also, If the combobox is null, is there anyway to go to the first record in the combobox rather than an error popping up? Currently I get Run-time error '94' Invalid use of Null. This also occurs when there is no more selections available in the combobox. Could the selections wrap around back to the begging? Thank you.
I am trying to have 2 Command buttons to go to previous and next record based off an unbound combo box selections. I currently have the next command button code via VBA but I don't know how to do the opposite for a previous button. This is the code I am using for a next record:
Code:
Function AdvanceCombo(strForm As String, strControl As String)
'This function clears all entries on all listboxes on the form strForm
Dim c As Control
Dim F As Form
Dim I As Long
Dim cValue As String
Set F = Forms(strForm)
Set c = F(strControl)
cValue = c.Value
For I = 0 To c.ListCount - 1
If c.ItemData(I) = cValue Then c.Value = c.ItemData(I + 1)
Next I
End Function
And then for the Command button:
Code:
Private Sub NextLogbookRecord_Click()
AdvanceCombo Me.Name, "TPComboBOx"
TPComboBOx_AfterUpdate
End Sub
Anybody know how I could edit this code to do the opposite and go to previous record?
Also, If the combobox is null, is there anyway to go to the first record in the combobox rather than an error popping up? Currently I get Run-time error '94' Invalid use of Null. This also occurs when there is no more selections available in the combobox. Could the selections wrap around back to the begging? Thank you.
Last edited: