J
John S. Ford, MD
I'm using Access 97. I have written an event handler to control the
NotInList event for a combobox to display my own error message and not allow
the user place an inapproriate entry and then hits <Return>:
Private Sub cboListBox_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
MsgBox "You must enter a valid entry.", vbExclamation
Me.Undo
End Sub
The code works perfectly except for one thing. This same ComboBox also has
an event handler for the OnKeyPress event that moves the focus to a subform
on the main form if the user hits <Return>. (This is to facilitate ease of
data entry.) If the user is entering incorrect info into the ComboBox, I'd
like the focus to STAY in the ComboBox and not advance to the next entry
field. I tried inserting a Me.SetFocus line at the end of the above code
but this generates an error message (Error #2449, invalid method in
expression).
Any simple way to resolve this? Can I somehow "cancel" the OnKeyDown event
in my code?
John
NotInList event for a combobox to display my own error message and not allow
the user place an inapproriate entry and then hits <Return>:
Private Sub cboListBox_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
MsgBox "You must enter a valid entry.", vbExclamation
Me.Undo
End Sub
The code works perfectly except for one thing. This same ComboBox also has
an event handler for the OnKeyPress event that moves the focus to a subform
on the main form if the user hits <Return>. (This is to facilitate ease of
data entry.) If the user is entering incorrect info into the ComboBox, I'd
like the focus to STAY in the ComboBox and not advance to the next entry
field. I tried inserting a Me.SetFocus line at the end of the above code
but this generates an error message (Error #2449, invalid method in
expression).
Any simple way to resolve this? Can I somehow "cancel" the OnKeyDown event
in my code?
John