Last Active Control

  • Thread starter Thread starter Robert Neville
  • Start date Start date
R

Robert Neville

How do you return the last Active Control when the control is on a tab
control? Screen.ActiveControl does not seem to work. Here's the
statement that my code uses.

Set ctlOld = Screen.ActiveControl

The code line work when all controls are placed on the form page
rather than a tab control. This code should pass the last active
control to the calling module. Then the following line requests the
tabindex from the control.
 
How do you return the last Active Control when the control is on a tab
control? Screen.ActiveControl does not seem to work. Here's the
statement that my code uses.
Set ctlOld = Screen.ActiveControl

Just tested on a tab control:
Debug.Print Screen.ActiveControl.Name
Debug.Print Screen.PreviousControl.Name

Both returned the correct control names.
The code line work when all controls are placed on the form page
rather than a tab control. This code should pass the last active
control to the calling module. Then the following line requests the
tabindex from the control.

?? Can you post the line that doesn't work?

Peter
 
Thanks Peter for your response.

Ok, the issue did not lie with the following statement.

Set ctlOld = Screen.ActiveControl

The dilemma related to the method the code enumerated through the
controls in conjunction with the tab order. My debugging efforts
alarmed me since the screen object did not register when activating a
watch on the variable. Further research outlined that the screen
object would not register if debugging through the VBA editor's window
since the Screen object is no longer the form or control.

Does any other method or function allow you to capture the active
control or previous control AND allow one to debug and watch the
variable? This information would help me develop more complex code
where debugging becomes essential.
 
Robert,
Ok, the issue did not lie with the following statement.
Set ctlOld = Screen.ActiveControl
The dilemma related to the method the code enumerated through the
controls in conjunction with the tab order. My debugging efforts
alarmed me since the screen object did not register when activating a
watch on the variable. Further research outlined that the screen
object would not register if debugging through the VBA editor's window
since the Screen object is no longer the form or control.
Does any other method or function allow you to capture the active
control or previous control AND allow one to debug and watch the
variable? This information would help me develop more complex code
where debugging becomes essential.

If debugging is the problem you can set the breakpoint _after_ this line:
Set ctlOld = Screen.ActiveControl

Then it will be executed on the right object, before changing to the code
window.

HTH - Peter
 
Back
Top