Error 2164 - Disabling a control while it has focus.

S

Stephan Ranocchia

I'm going to break something soon. Please read the following code
snippet:

If [Form_Site Information].subAuditHistoriesList.Form.RecordsetClone.RecordCount
= 0 Then
cmdLOB.SetFocus
** [Form_Site Information].subCurrentAudit.Form.cmdAuditHistory.Enabled
= False
Else
[Form_Site Information].subCurrentAudit.Form.cmdAuditHistory.Enabled
= True
End If

It craps out on the line with (**). Tells me that I can't disable a
control while it has focus. I guess it has chosen to ignore the line
directly above it.

Any thoughts? When I skip over the code, and return the form, I see
that the control cmdLOB does infact have focus, and not the button I'm
trying to disable.

Thanks,
SR
 
R

Rick Brandt

Stephan Ranocchia said:
I'm going to break something soon. Please read the following code
snippet:

If [Form_Site Information].subAuditHistoriesList.Form.RecordsetClone.RecordCount
= 0 Then
cmdLOB.SetFocus
** [Form_Site Information].subCurrentAudit.Form.cmdAuditHistory.Enabled
= False
Else
[Form_Site Information].subCurrentAudit.Form.cmdAuditHistory.Enabled
= True
End If

It craps out on the line with (**). Tells me that I can't disable a
control while it has focus. I guess it has chosen to ignore the line
directly above it.

Any thoughts? When I skip over the code, and return the form, I see
that the control cmdLOB does infact have focus, and not the button I'm
trying to disable.

The problem is that setting focus to a control in the main form does not
cause a control in a sub-form to lose focus. You need to move focus *in
the sub-form* to a control other than the one you want to disable. Then it
will work.
 

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