Click event triggers in the wrong command

B

Bob Richardson

While typing in a drop-down list, the user click a button on the form. This
is triggering an onClick event in the Drop-down list, not in the button.
What's happening and how can I prevent the drop-down list from executing
it's click event?
 
A

Al Camp

Bob,
What are you trying to do with the button, and what is the code you have
behind it?
And... why are you performing any action while in the middle of the combo
entry?
 
D

Dirk Goldgar

Bob Richardson said:
While typing in a drop-down list, the user click a button on the
form. This is triggering an onClick event in the Drop-down list, not
in the button. What's happening and how can I prevent the drop-down
list from executing it's click event?

The combo box's Click event fires when its value is updated by user
action, immediately after the AfterUpdate event fires. So if the user
is typing in the list, and then clicks some other control such as a
command button, the combo box's value will be updated and its
AfterUpdate and Click events will fire -- *before* the Click event of
the command button. It's not a case of the wrong event firing, it's
that the combo's Click event fires first.

If you don't want the combo box's Click event to fire under those
circumstances, the only way you can do it is to undo the changes to the
combo box before moving the focus to some other control. The user could
press the Escape key to do this. I can't think of another way to
prevent the combo box's Click event from firing under these
circumstances, except by cancelling its BeforeUpdate event and undoing
the change by calling the control's Undo method. But that won't let the
focus move immediately to the command button or other control; instead,
the combo box will keep the focus until the user clicks on the button
again.

What exactly are you trying to accomplish by undoing the combo box?
Maybe there's a workaround.
 
G

Graham R Seach

Bob,

I can confirm that behaviour. Wierd huh!

I don't see a way of avoiding it, except to not use the combo's Click event.
Out of curiosity, why are you using the combo's Click event?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
L

Larry Daugherty

Bob,

It may be necessary to educate your users a bit. Every application
has its idiosyncrasies. The poor combobox is really acting just as
one might expect. If you had typed into a text box and hit a button
to close the form or move off the record while the cursor was still in
the textbox you wouldn't be surprised to find that data in the
underlying field. If your user(s) really want to know how to undo an
action in Access; tell them that hitting Escape once will clear what
they just typed (Undo the combobox), hitting Escape twice will remove
all changes since the form opened on the current record.

HTH
 
B

Bob Richardson

The opening screen of my MDB has a continuous view of the Contacts file. In
the header section I have a combo box to access a specific contact. As soon
as the user starts typing in the combo box, the list drops down, which of
course updates as she continues to type the name. After 3-4 letters you can
normally see your contact and then click on it, or arrow down and hit enter.
This opens another screen with all the data in a single sheet view (SSV).

After typing a few characters in the combo box it may be apparent that this
name is not in the DB and must be added. At that time the user wants to
click the Add Contact button to open up the SSV which is all blank, ready
for input.

Two problems:
1. If her typing has singled out a specific contact, e.g. Smith, John, and
she clicks the Add Contact button (because she's looking for Smith, Mary -
who's not in the file) up pops John Smith's record ready for editing.
2. If a specific contact hasn't been singled out, then an error message pops
up telling her so. This isn't horrendous, but still a nag.

Whether I use the OnClick or AfterUpdate events on the combo doesn't seem to
make any difference, The Onclick for a Combo box seems to fire on just about
anything...close form, tab out.

I think the only solution is to train users to hit ESC before clicking the
Add Contact button. I was hoping that some event, perhaps a FORM event,
could be fired before the Combo's AfterUpdate, that would be able to undo
the combo box IF the Add Contact button were the trigger. Perhaps a button
mouseover event which could undo the combo box. From what I've found, the
button's mouse down event fires after the combo box's AfterUpdate...too
late.
 
G

Graham R Seach

Bob,

I see what you're trying to do, but might I suggest that you use a different
approach.

Try adding another record to the combo - an "Add New" record. See the
http://www.mvps.org/access/forms/frm0043.htm for information about how to do
that. The article talks about adding "All" to the list, but you can easily
change that to "Add New".

Secondly, you can make use of the combo's NotInList event to add the new
record, rather than relying on a separate control (the button). See
http://www.pacificdb.com.au/MVP/Code/NIL.htm for information about how to do
that.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
B

Bob Richardson

Thanks Graham, I went with the NotInList event.

Graham R Seach said:
Bob,

I see what you're trying to do, but might I suggest that you use a
different approach.

Try adding another record to the combo - an "Add New" record. See the
http://www.mvps.org/access/forms/frm0043.htm for information about how to
do that. The article talks about adding "All" to the list, but you can
easily change that to "Add New".

Secondly, you can make use of the combo's NotInList event to add the new
record, rather than relying on a separate control (the button). See
http://www.pacificdb.com.au/MVP/Code/NIL.htm for information about how to
do that.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Top