Conditional Statement based on active control

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

I'd like to run an If Then statement based on the following:

When I click a button I want my program to perform an action depending on
which textbox currently has the focus. I can't figure out how to write the
code that says

If txtA (has the focus) Then
(Some code)
Else
If txtB (has the focus) Then
(Some code)
End If
End If

Can someone help me with the syntax.
Thank you.
 
Select Case Screen.ActiveControl.Name
Case "txtA"
' some code
Case "txtB"
' some code
Case Else
' some other control has focus
End Select
 
if you click a command button on a form, the button has the focus, unless
you direct the focus elsewhere in the code.

hth
 
Excellent point, Tina!

Fortunately, Access not only has ActiveControl, but PreviousControl as well.
That means the sample code I posted previously probably needs to be

Select Case Screen.PreviousControl.Name
Case "txtA"
' some code
Case "txtB"
' some code
Case Else
' some other control has focus
End Select
 
i use ActiveControl sometimes, but i keep forgetting about PreviousControl
(use it or lose it - it's that whole age thing - at least, that's my story
and i'm stickin' to it! <g>). and i shouldn't, because sometimes it would
come in so handy. thanks for the reminder, Doug! :)
 
Back
Top