lost focus

J

johnlute

I have and Exit Event that forces a selection to be made in a
combobox:

Private Sub cbFacility_Exit(Cancel As Integer)
If IsNull(Me!cbFacility) Then
Beep
MsgBox "A Facility ID is required!"
Cancel = True
End If

End Sub

I want to kill this event when the focus is lost to the Cancel button
"cmdCancel". Does anyone have any ideas how I can do this?

Thanks in advance!
 
K

Ken Snell [MVP]

Cannot do. Instead, use the form's BeforeUpdate event to test for an empty
cbFacility_Exit value, and force user to select a value then.
 
J

johnlute

Thanks, Ken. I'm not sure I follow. And perhaps I wasn't clear.

I don't want to force the user to select a value. I want them to be
able to exit "cbFacility" IF and ONLY if they're trying to click the
cancel button.

The form is used to filter a query. cbFacility needs a selection in
order to requery other controls however if a user opens the form and
then decides to cancel they get the exit error msgbox which can create
confusion as if they've done something wrong and MUST run the query.

Is this how you understood it and am I misunderstanding your response?

Thanks!
 
K

Ken Snell [MVP]

You cannot selectively enforce when the Exit event occurs and when it does
not. If you put code in the Exit event procedure that refuses to let the
person leave the control unless the user selects something, then that is
what happens -- no matter the reason why the user wants to leave the
control.

So either you require the user to select something just so that the user
then can click the Cancel button, or you do not require the user to select
anything in the combobox at all -- at least not via the Exit event.

How do you "trigger" the running of the query that uses the form's combobox?
If by a button on the form, use that button's Click event to do your
validity check. Or, if no selection in the combobox can be interpreted as
"return all records unfiltered", change the criterion (WHERE clause) in your
query to handle this:

FieldName = Forms!NameOfForm!cbFacility OR Forms!NameOfForm!cbFacility IS
NULL

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/



Thanks, Ken. I'm not sure I follow. And perhaps I wasn't clear.

I don't want to force the user to select a value. I want them to be
able to exit "cbFacility" IF and ONLY if they're trying to click the
cancel button.

The form is used to filter a query. cbFacility needs a selection in
order to requery other controls however if a user opens the form and
then decides to cancel they get the exit error msgbox which can create
confusion as if they've done something wrong and MUST run the query.

Is this how you understood it and am I misunderstanding your response?

Thanks!
 
J

johnlute

Thanks, Ken! I'm reviewing per your comments and tinkering with the
button click event. I think that might be the best solution.

Thanks!
 
J

John W. Vinson

I have and Exit Event that forces a selection to be made in a
combobox:

What provision do you have (or do you need one!) for a user opening the form,
working with other controls, and never setting focus to the combo box AT ALL?
 
J

johnlute

Hi, John.

The form is very simple. It only has 5 controls and when it opens the
cursor is in cbFacility by virtue of it being first in the tab order.

The Exit Event is simply to assure that a selection is made. Maybe
this isn't the "best" way of doing it however I was just trying to
keep things simple.

It never occurred to me that this would be a problem should a user
change their mind and wish to cancel without running the query however
this is a desireable action now.
 

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

Similar Threads


Top