know which control has focus when button is clicked

M

mcnews

i am working on an error reporting system for a data entry application.
the user will click a button that opens an error reporting form on
which the user enters info about missing or questionable data. the
user will ship off a spreadsheet that contains a list of errors to be
corrected by the sneder of the original data entry form that is used by
the user to enter data into this system. we would like to be able to
automatically update the questions with the corrected data. so i need
to know which control had focus when the button was clicked so that i
can write that info to the errorlog.

how do know which control has focus is my question.

tia,
mcnewsxp
 
S

Stefan Hoffmann

hi,
how do know which control has focus is my question.
Your button gets the focus when clicked.

Use:

Screen.PreviousControl

Caution:

Test it always with

If Screen.PreviousControl Is Nothing Then
' There was a previous focused control.
End If


tia,
mcnewsxp
Nice, really.


mfG
--> stefan <--
 
M

mcnews

Stefan said:
hi,

Your button gets the focus when clicked.

Use:

Screen.PreviousControl

Caution:

Test it always with

If Screen.PreviousControl Is Nothing Then
' There was a previous focused control.
End If

PreviousControl does not have a Name property.
this is an Access ADP, BTW.

?
 
S

Stefan Hoffmann

hi,
Stefan Hoffmann wrote:
PreviousControl does not have a Name property.
Give it a try:

Private Sub cmdTestPreviousControl_Click()

Dim cb As Access.CommandButton
Dim ct As Access.Control
Dim tb As Access.TextBox

If Not Screen.PreviousControl Is Nothing Then
Set ct = Screen.PreviousControl
Select Case True
Case TypeOf ct Is Access.CommandButton
Set cb = ct
MsgBox cb.Name
Case TypeOf ct Is Access.TextBox
Set tb = ct
MsgBox tb.Name
Case Else
MsgBox "not testet control type."
End Select
End If

End Sub

this is an Access ADP, BTW.
This doesn't matter.

mfG
--> stefan <--
 
B

Brendan Reynolds

The 'IntelliSense' feature in VBA doesn't list the property, because it
doesn't 'know' in advance what type of control PreviousControl will be
pointing to when the code runs. It might be a text box, a label, a command
button, etc. So the 'IntelliSense' feature can't predict what properties the
actual control may have. But even though the 'IntelliSense' feature doesn't
list it, you can still use it, and it will work as long as the actual
control has a Name property - and I'm not aware of any type of control that
doesn't.
 

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