Access 2003 Setfocus

  • Thread starter Thread starter David
  • Start date Start date
D

David

I need to remember the focal location on a form before I execute some code,
so that I can setfocus back to that location after the code is executed.

The original focal location can be any field on the form most likely a combo
box. I tried running a command like.

currentloc = Selection.Formfields(1).Name

To save the original location.

I would like to do a .setfocus command to get back to the original location.

I can't find the exact code to make this happen. Any ideas?

Thanks,

Dave
 
Had an application that does something simual to what you describe. How are
you running the code? (button click or other method). The one I had used a
button. on the lostfocus event for the fields I stored the field name to a
variable. on the on click event of the button I use the docmd.gotocontrol to
set focus back to the last field selected before clicking the button.

-----------Begin code ------------
Dim s_Prev As String

Private Sub cbo01_Name_LostFocus()
s_Prev = Me.cbo01_Name.Name
End Sub

Private Sub cmd01_Ok_Click()
DoCmd.GoToControl s_Prev

End Sub
------------ End Code --------------
 
I'm trying to run the code off of the form current event. It seems to
execute anytime someone clicks on a combobox in the body of the form. It
could be because I have refresh code attached to each combobox. I think I
am running into a problem because the code is attached to the form and not
the combobox. Any ideas?
 
try

If Not s_Prev = "" Then
DoCmd.GoToControl s_Prev
End If

in the on current event for the form. Need the if to check if a value has
been placed in s_prev to prevent error on first record displayed. still use
the lost focus event to store the name of the field into s_Prev.
 
Your code worked! Yeah I needed to store the field name in the focus
command.

Thank you very much!
 

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

Back
Top