Conditional Statement based on active control

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.
 
D

Douglas J. Steele

Select Case Screen.ActiveControl.Name
Case "txtA"
' some code
Case "txtB"
' some code
Case Else
' some other control has focus
End Select
 
T

tina

if you click a command button on a form, the button has the focus, unless
you direct the focus elsewhere in the code.

hth
 
D

Douglas J. Steele

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
 
T

tina

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! :)
 

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