Combobox event

P

Paul

In a Access form I assign an "After Update" event to a combobox. If certain
value in the droplist of the combobox is selected, it will do a bunch of
things. What I need to do is make sure one of the textbox named "Textbox1"
has to be filled in before the "After Update" event kick in, if it is empty
it should not execute the "After Update" event and reverse the combobox
value back to the value before. What event should I use? "Dirty" or "Before
Update" event and how do I stop the "After Update" event and de-select the
droplist value if the textbox1 is empty. Thanks
 
B

BruceM via AccessMonster.com

In the combo box After Update event, something like this:

If Nz(Me.Textbox1,"") = "" Then
MsgBox "You need something in Textbox1"
Me.ComboBoxName.Undo
Cancel = True
End If

If you can be sure Textbox1 is null if it is empty the first line could be:

If IsNull(Me.Textbox1) Then

Alternatively:

If Me.Textbox1 & "" = "" Then
 
J

J_Goddard via AccessMonster.com

The After Update event does not have the Cancel option.

You should put this check in the Before update event, which does have the
Cancel.

John


In the combo box After Update event, something like this:

If Nz(Me.Textbox1,"") = "" Then
MsgBox "You need something in Textbox1"
Me.ComboBoxName.Undo
Cancel = True
End If

If you can be sure Textbox1 is null if it is empty the first line could be:

If IsNull(Me.Textbox1) Then

Alternatively:

If Me.Textbox1 & "" = "" Then
In a Access form I assign an "After Update" event to a combobox. If certain
value in the droplist of the combobox is selected, it will do a bunch of
[quoted text clipped - 4 lines]
Update" event and how do I stop the "After Update" event and de-select the
droplist value if the textbox1 is empty. Thanks
 
B

BruceM via AccessMonster.com

Oops. You are correct, of course. To the OP, the After Update event can be
used to do things such as set the Row Source of another combo box based on
the one just updated, hide or unhide controls, and such, but it is not a good
event for data validation. Depending on what the "bunch of things" are you
may want to do some in the After Update event.

J_Goddard said:
The After Update event does not have the Cancel option.

You should put this check in the Before update event, which does have the
Cancel.

John
In the combo box After Update event, something like this:
[quoted text clipped - 17 lines]
 

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