From: johnlute on
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!
From: Ken Snell [MVP] on
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.

--

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


"johnlute" <jlute(a)marzetti.com> wrote in message
news:1ac95c9e-0e27-4c6b-b9f1-e11c87672e26(a)s39g2000yqj.googlegroups.com...
>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!


From: johnlute on
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!

On Sep 3, 9:04 am, "Ken Snell [MVP]"
<kthsneisll...(a)ncoomcastt.renaetl> wrote:
> 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.
>
> --
>
>         Ken Snell
> <MS ACCESS MVP>http://www.accessmvp.com/KDSnell/
>
> "johnlute" <jl...(a)marzetti.com> wrote in message
>
> news:1ac95c9e-0e27-4c6b-b9f1-e11c87672e26(a)s39g2000yqj.googlegroups.com...
>
>
>
> >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!- Hide quoted text -
>
> - Show quoted text -

From: Ken Snell [MVP] on
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/



"johnlute" <jlute(a)marzetti.com> wrote in message
news:a1b860f9-8a41-43ac-8da2-d49758c81ecf(a)g31g2000yqc.googlegroups.com...
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!

On Sep 3, 9:04 am, "Ken Snell [MVP]"
<kthsneisll...(a)ncoomcastt.renaetl> wrote:
> 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.
>
> --
>
> Ken Snell
> <MS ACCESS MVP>http://www.accessmvp.com/KDSnell/
>
> "johnlute" <jl...(a)marzetti.com> wrote in message
>
> news:1ac95c9e-0e27-4c6b-b9f1-e11c87672e26(a)s39g2000yqj.googlegroups.com...
>
>
>
> >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!- Hide quoted text -
>
> - Show quoted text -


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

Thanks!

On Sep 3, 3:00 pm, "Ken Snell [MVP]"
<kthsneisll...(a)ncoomcastt.renaetl> wrote:
> 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/
>
> "johnlute" <jl...(a)marzetti.com> wrote in message
>
> news:a1b860f9-8a41-43ac-8da2-d49758c81ecf(a)g31g2000yqc.googlegroups.com...
> 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!
>
> On Sep 3, 9:04 am, "Ken Snell [MVP]"
>
>
>
> <kthsneisll...(a)ncoomcastt.renaetl> wrote:
> > 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.
>
> > --
>
> > Ken Snell
> > <MS ACCESS MVP>http://www.accessmvp.com/KDSnell/
>
> > "johnlute" <jl...(a)marzetti.com> wrote in message
>
> >news:1ac95c9e-0e27-4c6b-b9f1-e11c87672e26(a)s39g2000yqj.googlegroups.com....
>
> > >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!- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -