Update event for a Combo box - not a biggie

G

Guest

This is not a big deal but I can't seem to find an answer to my question. I
have a form with a button (cmdFilter) which I enable/disable based on certain
situations. One of the situations that I want to enable the button is if the
user selects a new listing from a combo box. Everything works fine
except....what if the combo box is on the first item in the list (button is
disabled) and the user pops up the combo box but leaves it on item 1. The
data in the box hasn't really changed but still the AfterUpdate event fires
as does the OnChange and the button gets enabled. I would prefer that the
button only be enabled if there is a new item in the combo box. Is there a
way to accomplish this?
 
J

John Spencer

Is the combobox bound to a field? If so, you can check its old value and if
it is different then the value of the combobox has changed. If this is a
new record, then you have a problem of the old value might be null.

Or Dim a form-level variable. Set its value with the combox's gotFocus
event to the value of the combobox. Then in the after update event compare
the variable value to the combobox's value and if they are the same don't
activate your control.



--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
G

Guest

You don't say how you are adding new items, so an absolute answer is
impossible. There are some ideas I can share.
First, you really don't want the Change event. It fires for every change.
That means it fires for every keystroke. You might use the After Update
event of the combo by testing to see if the value has changed
If Me.cboFoo <> Me.cboFoo.OldValue Then
The comb has changed

But, you still don't know if it is a new item in the list.
The best way would be to use the combo's Not In List event. This event is
commonly used to add new records or at least new items to the list. If you
allow the new entry, you could make the command button enabled there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top