Access Problem: Combobox.setfocus fires combobox.OnClick event

H

Hal Levy

I am doing a .SetFocus against a ComboBox.... all of a sudden I am getting
errors when the .SetFocus is called. I have narrowed this down to the .
ComboBox_Click routine being called when the .SetFocus takes place. There
is no code for the .SetFocus event. I can not for the life of me figure out
why it's raising the ,OnClick event.

Anyone have any ideas?
 
K

Klatuu

If you are clicking on the combo box to set the focus to it, the Click event
will fire (you just clicked on it). If you tab to it, the Click event will
not fire.

Prehaps you can describe what it is you are trying to do and maybe we can
help find a way that will work for you.
 
D

Dirk Goldgar

Hal Levy said:
I am doing a .SetFocus against a ComboBox.... all of a sudden I am getting
errors when the .SetFocus is called. I have narrowed this down to the .
ComboBox_Click routine being called when the .SetFocus takes place. There
is no code for the .SetFocus event. I can not for the life of me figure
out
why it's raising the ,OnClick event.

Anyone have any ideas?


That shouldn't happen. Do you have any code in other events of the combo
box? The Enter event should also fire when you SetFocus to it.

From what event are you executing the SetFocus?
 
H

Hal Levy

That shouldn't happen. Do you have any code in other events of the
combo box? The Enter event should also fire when you SetFocus to it.

From what event are you executing the SetFocus?

- the only event on the combo box is On Click

- A button is clicked to cancel changes on a form. That button calls a form
cleanup routine. The cleanup does a cmbControl.text = "". I need to give
the control focus before doing that. So, I do a cmbControl.SetFocus. As
soon as the cmbControl.SetFocus is called it calls the On Click event for
the cmbControl. There is no mouse click or tabbing around. The focus is
called programatically- so I don't think it should be setting off the On
Click event.
 
D

Dirk Goldgar

Hal Levy said:
- A button is clicked to cancel changes on a form. That button calls a
form
cleanup routine. The cleanup does a cmbControl.text = "". I need to give
the control focus before doing that. So, I do a cmbControl.SetFocus. As
soon as the cmbControl.SetFocus is called it calls the On Click event for
the cmbControl. There is no mouse click or tabbing around. The focus is
called programatically- so I don't think it should be setting off the On
Click event.


Are you sure that it isn't your assignment to the cobo box's Text property
that is triggering the Click event? Normally, assignments to a control's
Value property do not trigger events, but assignments to the Text property
do. I can verify that assigning to the combo box's Text property *will*
fire the Click event. This is because it's treated like a manual update of
the combo box (by typing into it), and all manual updated of a combo box
fire the Click event.

HOWEVER, you do not need to assign to the Text property to clear the combo
box. If you assign to the combo box's Value property instead (its default
property), you don't need to set the focus to it at all. This is one way in
which Access controls differ from VB controls. The Text property has very
limited use and is only available when the control has the focus, but the
Value property has general use and is available anytime.

So, instead of this:

Me.cmbControl.SetFocus
Me.cmbControl.Text = ""

.... do this:

Me.cmbControl = Null

.... or possibly, if you really need to set the value to a zero-length string
(which I think unlikely), this:

Me.cmbControl = ""
 
L

Linq Adams via AccessMonster.com

"A button is clicked to cancel changes on a form"

IF this is so, wht not simply

Me.Undo
 
D

Dirk Goldgar

Linq Adams via AccessMonster.com said:
"A button is clicked to cancel changes on a form"

IF this is so, wht not simply

Me.Undo


I was assuming it was an unbound combo, but if not then your suggestion is
clearly correct. Setting a combo box to "" or Null is certainly not the
same as "undoing" it.
 

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