If statement involving cursor possition

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If the cursor is on a certain textbox when I press a command button I want
the system to perform a certain task.
However how can I check in VBA if the cursor is on that textbox?
Thanks in advance

Michalis
 
Screen.ActiveControl.Name
will return the name of the control where the cursor is located.
 
Michalis said:
If the cursor is on a certain textbox when I press a command button I want
the system to perform a certain task.
However how can I check in VBA if the cursor is on that textbox?


If Screen.PreviousControl.Name = "textboxname" Then
 
If the cursor is on a textbox in a subform and the command button on the main
form is this still supposed to work?
 
No. The focus must move back to the main form when you
click the command button so the "cursor" is no longer on
your text box. PreviousControl will work if both controls
are on the same form, but the subform control on the main
form is the previous control when the main form button
becomes the active control.

However, you can use the subform control's Exit event to
save the name of the Active control.
Me.hiddentextbox = Screen.ActiveControl.Name
Then the button can check the saved name against the certain
text box:
If Me.hiddentextbox = "certaintextboxname" Then
 
Thanks a lot Barton. It works just fine.
Michalis

Marshall Barton said:
No. The focus must move back to the main form when you
click the command button so the "cursor" is no longer on
your text box. PreviousControl will work if both controls
are on the same form, but the subform control on the main
form is the previous control when the main form button
becomes the active control.

However, you can use the subform control's Exit event to
save the name of the Active control.
Me.hiddentextbox = Screen.ActiveControl.Name
Then the button can check the saved name against the certain
text box:
If Me.hiddentextbox = "certaintextboxname" Then
--
Marsh
MVP [MS Access]

If the cursor is on a textbox in a subform and the command button on the main
form is this still supposed to work?
 
Back
Top