read focus of controls

I

iccsi

I would like to set enabled to false, but sometimes the command button
is on focus that I got error that I can not disabled controls when it
is on focus.

I wanted to check if it is on focus before disabled it, but I onlt
find SetFocus method.

Any property to read focus of the controls to check does the controls
are in focus?

Any information is great appreciated,
 
M

Marshall Barton

iccsi said:
I would like to set enabled to false, but sometimes the command button
is on focus that I got error that I can not disabled controls when it
is on focus.

I wanted to check if it is on focus before disabled it, but I onlt
find SetFocus method.

Any property to read focus of the controls to check does the controls
are in focus?

Since only one control on a form can have the focus, you can
just check to see if the control is the active control.

If Me.ActiveControl Is Me.somecontrol Then
Me.somecontrol.Enabled = False
End If

But, if you are using a command button on the same form to
disable itself, the command button is guaranteed to have the
focus and that code will never disable the button. In this
case you need to set the focus to another control before
trying to disable the button. Maybe the control that had
the focus before the button would be appropriate. If so,
try using:

Screen.PreviousControl.SetFocus
Me.thebutton.Enabled = False

OTOH, if you are using a button to disable some other
control, you already know that the other control does not
have the focus, So, all you need would be:
Me.somecontrol.Enabled = False
but you said that the control you want to disable
"sometimes" has the focus. This implies that the code to
disable the control is in a different form than the control
so most of the above is irrelevant.
 

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