Run-time error '2185' in check box click event

T

Tony Girgenti

I have a combo box and a check box next to it on a form. If the check box
is checked, i'd like to make the combo box text say something and make it
not usable. When i try that from the check box onclick event, I get a
"Run-time error '2185': You can't reference a property or method for a
control unless the control has the focus"

So how do i make the combo box not usable while i'm in the click event for
the check box ?

Any help greatly appreciated.

Thanks, Tony
 
K

Ken Snell

Try code similar to this on the AfterUpdate (not Click) event of the
checkbox:

Private Sub chkBoxName_AfterUpdate()
Me.cboBoxName.Enabled = Not Me.chkBoxName.Value
End Sub

Above code will disable the combo box when the checkbox is clicked
(checkmark is showing), and reenable it when the checkbox is unchecked.
 
T

Tony Girgenti

Hi Ken. Thanks for your help.

I tried this and i get "Run-time error: '2164': You can't disable a control
while it has the focus."

Thanks,
Tony
 
T

Tony Girgenti

Hi Ken. Thanks for your help.

I tried this and i get "Run-time error: '2164': You can't disable a control
while it has the focus."

Thanks,
Tony
 
K

Ken Snell

? Are you sure you didn't mistype the code? This code will run while the
checkbox has the focus and will enable/disable the combo box (I used generic
names for checkbox and combobox controls -- substitute your real names).
 
T

Tony Girgenti

That works OK, but Iwant to do this. And it's not working.

If Me.StrItmChk = True Then
Me.StrItm.Text = """First"""
Me.StrItm.Enabled = False
StartItem = Hex(0)
Else
Me.StrItm.Text = ""
Me.StrItm.Enabled = True
StartItem = Hex(255)
End If
 
K

Ken Snell

On which event are you running this code? And which control has the focus
when the code would run?
 
T

Tony Girgenti

Hi Ken.

This code is running in the check box after update event and the check box
has the focus.

Tony
 
K

Ken Snell

By "not working", do you mean that the desired text value isn't being
written to the StrItem control? If that is it, you need to use the .Value
property, not the .Text property for that control.

In VBA, the .Text property is available *only when* the control has the
focus. The .Value property is available regardless of whether the control
has the focus or not.
 
T

Tony Girgenti

Hi Ken.

By "not working", i mean i get the '2185' error.
Your other thoughts on this problem might solve it for
me. I will let you know.

Thanks,
Tony
 
T

Tony Girgenti

Thanks Ken for all your help.
I used the Value property and that fixed it.

Thanks again and thanks to everybody else on this forum that does their
share to help others.

Tony
 

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