cricketbird
Registered User.
- Local time
- Today, 16:00
- Joined
- Jun 17, 2013
- Messages
- 112
I have a combobox that looks up the employeeid (user sees a list of employee names) to navigate to that record. Many folks who know the employee's ID number just type the ID number itself rather than scroll, and that works great too.
However, some folks occasionally type the user's name ("Jones") in instead, which obviously doesn't work.
I played around with adding some code to allow this, which ALMOST works great.
If you open the form and type a text string into the combo box you will immediately (before any code executes) get the error "The value you entered isn't valid for this field".
However, once you USE the combo box to navigate somewhere (anywhere), it will then work fine (allowing text searches) forever until you re-open the form. Somehow, after using the combobox once, Access no longer verifies that you've entered a number and allows my code to run. You can navigate between records, refresh, requery, and the combo box will still work great, but only after you use it (in the traditional way) once each time you open the form.
Any ideas on why it throws an error if you enter text the first time you use the combo box after opening the form, but doesn't later? And how to get that "later" behavior at the start?
Thank you!
However, some folks occasionally type the user's name ("Jones") in instead, which obviously doesn't work.
I played around with adding some code to allow this, which ALMOST works great.
If you open the form and type a text string into the combo box you will immediately (before any code executes) get the error "The value you entered isn't valid for this field".
However, once you USE the combo box to navigate somewhere (anywhere), it will then work fine (allowing text searches) forever until you re-open the form. Somehow, after using the combobox once, Access no longer verifies that you've entered a number and allows my code to run. You can navigate between records, refresh, requery, and the combo box will still work great, but only after you use it (in the traditional way) once each time you open the form.
Any ideas on why it throws an error if you enter text the first time you use the combo box after opening the form, but doesn't later? And how to get that "later" behavior at the start?
Thank you!
Code:
Private Sub Combo1_AfterUpdate()
Dim myVal As String
On Error GoTo Err_Handler
myVal = Me!Combo1
If IsNumeric(myVal) Then
<open form to appropriate employeeid>
Else
<open form to the first user where their name contains the search string>
End If
Err_Handler:
MsgBox "There is no user with that ID or name."
Exit Sub
End Sub