Which field had the focus

  • Thread starter Thread starter Estêvão Raminhos
  • Start date Start date
E

Estêvão Raminhos

Hi all,

I have a form with various fields to be filled in with numeric values. When
I push a certain command button I want to change the value of the field
(formula) where the cursor was before (field which had the focus). Any
ideas?

TIA

Estêvão Raminhos
(e-mail address removed)
 
One approach would be to put logic in the LostFocus event of each of the
fields and keep track of what the fieldname is. You can create a function in
the code behind your form along the lines of:

Dim mstrControl As String

Private Function LostFocus()
mstrControl = Screen.ActiveControl.Name
End Function

Then, in the LostFocus event for each control, simply put =LostFocus()
(remember that you can select all of the controls and then insert this same
function for all of them at once)

In your button's Click event, you can then refer to the value of
mstrControl.
 
Estêvão,

In addition to Doug's suggestion, the Screen object also has a
PreviousControl property. But you have to take care when there is NO
previous control.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Son of a gun. I never knew that! (but then, I've never needed this
functionality...)
 
Back
Top