Which field had the focus

  • Thread starter Estêvão Raminhos
  • 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)
 
D

Douglas J. Steele

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

Graham R Seach

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
 
D

Douglas J. Steele

Son of a gun. I never knew that! (but then, I've never needed this
functionality...)
 

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