Setting the Focus on a Specific Field after clicking "Add Record"

S

ssignore

Hello MS Online Community.
I created a database for another unit within my division with a primary data
entry form entitled Case Number Index Card Form. When the Users click on the
command button (on the Switchboard) which opens the form, they automatically
'land' in a brand new record with the cursor blinking in the Last Name field.
The users would also prefer that the cursor 'land' in the field "Last Name"
after they click the "Add Record" command button. [Currently, the cursor has
no home after "Add Record" is clicked and they need to use the mouse to put
the cursor in Last Name (which is the first field on the form.)]

I'm not well-versed in VBA; is there any way I can do this without scripting?
If not, what is the syntax needed?

Many thanks for the help!
Regards,
Simone
 
A

Al Campagna

ssignore,
Your Tab Order should be handling that. Your LastName field should
have the properties... TabStop = Yes, and TabIndex = 0. This will cause the
cursor will go to LastName control whenever you "open" the form to a
New record.
If going to a New Record from a previous record, where the cursor
could be in any control...use this code in the OnCurrent event of the
form...
This would be a good opportunity to move from macros to vba.

Find the OnCurrent property of your form.
Place your cursor in the text box associated with OnCurrent.
Click the arrow on the right of the text box to select "Event Procedure"
Click the 3 dot (...) button on the right of the text box.
You are now in the "module", where code is put, for the form.
You will see this...

Private Sub Form_Current()

End Sub

Type in this code between the lines...

Private Sub Form_Current()
If Me.NewRecord Then
DoCmd.GoToControl "LastName"
End If
End Sub

Close the module and return to form design.
Run the form, and this code should cause any New record entry
will start from the LastName control.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
S

ssignore

Ohhhh, I cannot believe I couldn't figure that out! (I've been trying to
'learn' VBA with a book, but haven't gotten to DoCmd.GoToControl yet,
evidently!)
Thank you so much, Al - works like a charm!
Much appreciated

Al Campagna said:
ssignore,
Your Tab Order should be handling that. Your LastName field should
have the properties... TabStop = Yes, and TabIndex = 0. This will cause the
cursor will go to LastName control whenever you "open" the form to a
New record.
If going to a New Record from a previous record, where the cursor
could be in any control...use this code in the OnCurrent event of the
form...
This would be a good opportunity to move from macros to vba.

Find the OnCurrent property of your form.
Place your cursor in the text box associated with OnCurrent.
Click the arrow on the right of the text box to select "Event Procedure"
Click the 3 dot (...) button on the right of the text box.
You are now in the "module", where code is put, for the form.
You will see this...

Private Sub Form_Current()

End Sub

Type in this code between the lines...

Private Sub Form_Current()
If Me.NewRecord Then
DoCmd.GoToControl "LastName"
End If
End Sub

Close the module and return to form design.
Run the form, and this code should cause any New record entry
will start from the LastName control.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."



ssignore said:
Hello MS Online Community.
I created a database for another unit within my division with a primary
data
entry form entitled Case Number Index Card Form. When the Users click on
the
command button (on the Switchboard) which opens the form, they
automatically
'land' in a brand new record with the cursor blinking in the Last Name
field.
The users would also prefer that the cursor 'land' in the field "Last
Name"
after they click the "Add Record" command button. [Currently, the cursor
has
no home after "Add Record" is clicked and they need to use the mouse to
put
the cursor in Last Name (which is the first field on the form.)]

I'm not well-versed in VBA; is there any way I can do this without
scripting?
If not, what is the syntax needed?

Many thanks for the help!
Regards,
Simone
 

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