Re: Canceling the OnKeyDown event

From: Dirk Goldgar (dg_at_NOdataSPAMgnostics.com)
Date: 11/29/04


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)


Relevant Pages

  • Re: Canceling the OnKeyDown event
    ... I have written an event handler to control the ... This same ComboBox ... disallow the update in the NotInList event, the AfterUpdate event won't ...
    (microsoft.public.access.formscoding)
  • How to defer NotInList handling until record is saved
    ... I have a combobox that allows users to select data from a lookup table. ... NotInList event fires so I can provide code to add the new data to the ... subsequent fields to properly add the data to the lookup tables. ...
    (microsoft.public.access.formscoding)
  • Re: validation rule on combo box
    ... you want a custom message rather than the default Access message. ... Check Access VB Help on the NotInList Event of ComboBox. ... "Gerald Stanley" wrote in message ...
    (microsoft.public.access.forms)
  • RE: ComboBox LimitToList/Dropdown problem
    ... You can find the NotInList event going through the code page. ... Open the code page, on the combobox on top at left, select your combobox, ... > Private Sub cboContact_NotInList ... > Dim intAddRow As Integer ...
    (microsoft.public.access.forms)
  • Re: Combo Boxes
    ... box based upon the selection made in the first combo box. ... The combobox property that determines what is shown in the ... populated with an SQL statement telling Access what to show ... put in the GotFocus event handler of the second combo box. ...
    (microsoft.public.access.forms)

Loading