Re: Canceling the OnKeyDown event
From: Dirk Goldgar (dg_at_NOdataSPAMgnostics.com)
Date: 11/29/04
- Next message: ckerns_at_REfuse.net: "How to set reference to XL 95?"
- Previous message: AlCamp: "Re: Toggle versus Command"
- In reply to: John S. Ford, MD: "Canceling the OnKeyDown event"
- Next in thread: John S. Ford, MD: "Re: Canceling the OnKeyDown event"
- Reply: John S. Ford, MD: "Re: Canceling the OnKeyDown event"
- Reply: John S. Ford, MD: "Re: Canceling the OnKeyDown event"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 29 Nov 2004 18:15:28 -0500
"John S. Ford, MD" <johnsfordNOSPAMmd@hotmail.com> wrote in message
news:uifqXRm1EHA.2716@TK2MSFTNGP14.phx.gbl
> 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?
Is the behavor when the user hits {Enter} intended to be different from
the behavior when the user types a value in the combo box and presses
{Tab}, or from when the user uses the mouse to drop down the combo's
list and select a value? If not, then it seems to me your end would be
better served by using the combo box's AfterUpdate event, rather than
the KeyDown event, to send the focus to the subform. That way, if you
disallow the update in the NotInList event, the AfterUpdate event won't
fire and the focus will stay in the combo box.
-- Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup)
- Next message: ckerns_at_REfuse.net: "How to set reference to XL 95?"
- Previous message: AlCamp: "Re: Toggle versus Command"
- In reply to: John S. Ford, MD: "Canceling the OnKeyDown event"
- Next in thread: John S. Ford, MD: "Re: Canceling the OnKeyDown event"
- Reply: John S. Ford, MD: "Re: Canceling the OnKeyDown event"
- Reply: John S. Ford, MD: "Re: Canceling the OnKeyDown event"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|