How hide combobox without selection?

G

Guest

StaffPickComBx is not visible until an Add button is clicked. Visible is set
to True and the combobox drops down, waiting for a selection. I would like
to allow the user to change his mind without selecting anything, causing the
combobox to disappear. The most intuitive triggers, I think, are [Esc] and a
click anywhere else on the form. But I can't see how to trap those.
Suggestions?

Thanks!
 
S

Sam

Hi Dave,

You can try this, until someone offers a neater and more efficient
method!

On your form, under the on click event code, set an IF statement.

Rough example:

IF comboBox.visible = TRUE AND IsNull(comboBox.value) THEN
comboBox.visible = FALSE
END IF

You say the combo box is made visible when the user clicks a push
button?

If circumstances allow, consider using two radio buttons. where one
would enable/show the combo box, and the other would disable/hide it.

Hope this helped a little,

Kind Regards,
Sam
 
G

Guest

Thanks, Sam, but that won't quite do it. I can't see which OnClick event to
use to trap the click outside of the combobox, which would be the intuitive
action. It would be nice to trap [Esc] for this purpose, too.
 
M

Marshall Barton

LongWayFromHome said:
Thanks, Sam, but that won't quite do it. I can't see which OnClick event to
use to trap the click outside of the combobox, which would be the intuitive
action. It would be nice to trap [Esc] for this purpose, too.


Esc means something else, specifically to undo any changes
to the current control (the combo box). If the user selects
something from the list and changes her mind, then she would
hit Esc to return the combo box to its previous state.

You can use the combo box's Exit event to run Sam's
suggested code.
 
G

Guest

I must not be clear about what I'd like to do: if the combox is Null and the
user clicks anywhere else on the form (in a control or not) the event is
triggered. OnExit seems to require clicking on another control, but I'd also
like to monitor the space between controls, if that is possible.

--
Dave


Marshall Barton said:
LongWayFromHome said:
Thanks, Sam, but that won't quite do it. I can't see which OnClick event to
use to trap the click outside of the combobox, which would be the intuitive
action. It would be nice to trap [Esc] for this purpose, too.


Esc means something else, specifically to undo any changes
to the current control (the combo box). If the user selects
something from the list and changes her mind, then she would
hit Esc to return the combo box to its previous state.

You can use the combo box's Exit event to run Sam's
suggested code.
 
G

Guest

I understand what you want, and I worked on solving this problem for about 30
minutes. Here's the best I could come up with:

In your combo box's OnLostFocus event, code something like this:

If IsNull(Me.comboBox.Value) Then
DoCmd.GoToControl [some other control on your form]
Me.comboBox.Visible = False
End If

(You have to GoTo another control on your form before you hide the combo box
because if you don't you'll get an error message saying something like "you
can't hide a control that has the focus")

So...that takes care of it the user clicks in another control. Now, to hide
the combo box if they just click outside of it, I figured I could just put
that same code in the OnClick event of the Detail section of your form. But
for some crazy reason, when I put that exact code in the OnClick event of the
Detail section, it spit me out an error on the GoToControl line, saying it
"couldn't go to control [controlName]"

So if you know of a way to take focus off of the combo box programatically
without moving to another control, then above code could work in both places
and you'd be in business, but I don't know how to do it.

That's all I got. Good luck.

-ndalton
 
G

Guest

That's it! Here is the exact code for me:

Private Sub Detail_Click()
If IsNull(Me.StaffPickComBx) And Me.StaffPickComBx.Visible = True Then
Me.AssocStaffLstBx.SetFocus
Me.StaffPickComBx.Visible = False
End If
End Sub

Thank you! Have a GREAT weekend!
--
Dave


ndalton said:
I understand what you want, and I worked on solving this problem for about 30
minutes. Here's the best I could come up with:

In your combo box's OnLostFocus event, code something like this:

If IsNull(Me.comboBox.Value) Then
DoCmd.GoToControl [some other control on your form]
Me.comboBox.Visible = False
End If

(You have to GoTo another control on your form before you hide the combo box
because if you don't you'll get an error message saying something like "you
can't hide a control that has the focus")

So...that takes care of it the user clicks in another control. Now, to hide
the combo box if they just click outside of it, I figured I could just put
that same code in the OnClick event of the Detail section of your form. But
for some crazy reason, when I put that exact code in the OnClick event of the
Detail section, it spit me out an error on the GoToControl line, saying it
"couldn't go to control [controlName]"

So if you know of a way to take focus off of the combo box programatically
without moving to another control, then above code could work in both places
and you'd be in business, but I don't know how to do it.

That's all I got. Good luck.

-ndalton



LongWayFromHome said:
I must not be clear about what I'd like to do: if the combox is Null and the
user clicks anywhere else on the form (in a control or not) the event is
triggered. OnExit seems to require clicking on another control, but I'd also
like to monitor the space between controls, if that is possible.
 
G

Guest

Well, it will have to be close enough. On further testing, I encouintered
the same problem ndalton described. Apparently, the sequence runs like this:

Private Sub Detail_Click()
Me.AssocStaffLstBx.SetFocus
THEN
Private Sub StaffPickComBx_LostFocus()
Me.StaffPickComBx.Visible = False
Me.StaffPickComBx.Visible = False
End (Combox) Sub
THEN RETURN TO
Me.AssocStaffLstBx.SetFocus (Crash here.)
End (Detail) Sub

I tried various tricks around this with no more luck than ndalton.

Any insight -- and particularly any workaround -- would be appreciated.

Thanks.
 
M

Marshall Barton

LongWayFromHome said:
I must not be clear about what I'd like to do: if the combox is Null and the
user clicks anywhere else on the form (in a control or not) the event is
triggered. OnExit seems to require clicking on another control, but I'd also
like to monitor the space between controls, if that is possible.


The exit event covers the cases when the user clicks, tabs,
or whatever to another control or another section that can
receive the focus.

You can use the detail section's click event to deal with
clicks in a blank area between controls.

The one thing that is not covered by the above is unattached
labels. If you have any of these, then use each one's click
event to run the code.

Note that the LostFocus event will fire when the focus moves
anywhere else on the screen, not just for actions within
this one form. For actions within the form the two events
are very similar.
 

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