Working with a combo box record selector.
Q: Debbie Sabia writes that she has created a form with a record selector combo box. The end user selects an ID from the combo box and correct data is pulled up on that student. Here’s the problem. When you use the record selector to go to record #2 the ID field doesn’t change on the form. I would like for the users to be able to choose an ID from the combo or scroll through the data with the record selector.
A: The combo box record selector should be unbound — it is just used to move to another record. To avoid confusion, I usually place this combo box in the form header or footer. Then you can have a regular bound ID field in the body of the form, which will change as you move from record to record. Here is the standard code I put on a record selector combo box for a numeric ID:
Private Sub cboSelect_AfterUpdate()
On Error GoTo ErrorHandler
Dim strSearch As String
strSearch = “[______ID] = ” & Me![cboSelect]
‘Find the record that matches the control
Me.RecordsetClone.FindFirst strSearch
Me.Bookmark = Me.RecordsetClone.Bookmark
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox “Error No: ” & Err.Number & “; Description: ” & _
Err.Description
Resume ErrorHandlerExit
End Sub