Need help with VBA statement to get name of active control

  • Thread starter Thread starter BobV
  • Start date Start date
B

BobV

Group:

What is the VBA statement to obtain the name of the active form's control
that currently has the focus? I have a form with several combo boxes on it,
and I want to get the name of the combo box that has the focus. Any help
will be greatly appreciated.

Thanks,
BobV
 
Group:

What is the VBA statement to obtain the name of the active form's control
that currently has the focus? I have a form with several combo boxes on it,
and I want to get the name of the combo box that has the focus. Any help
will be greatly appreciated.

Thanks,
BobV

Look up ActiveControl in VBA help.
While there also look up PreviousControl.
 
Fred:

Thank you for the help. ActiveControl is what I needed. Here is the VBA
statement that I used to get the name of the combo box that currently has
focus:

Dim Cntrl as Control
Dim CntrlName as String
Set Cntrl = Screen.ActiveControl
CntrlName = Cntrl.Name

Thanks,
BobV
 
If all you need is the name of the control, the following might be faster:

Dim CntrlName as String

CntrlName = Screen.ActiveControl.Name


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



BobV said:
Fred:

Thank you for the help. ActiveControl is what I needed. Here is the VBA
statement that I used to get the name of the combo box that currently has
focus:

Dim Cntrl as Control
Dim CntrlName as String
Set Cntrl = Screen.ActiveControl
CntrlName = Cntrl.Name

Thanks,
BobV
 
Doug:

Good point.

Thanks,
BobV

Douglas J. Steele said:
If all you need is the name of the control, the following might be faster:

Dim CntrlName as String

CntrlName = Screen.ActiveControl.Name
 
Back
Top