Cursor after adding new record

A

Al V

If I put a button on a form, using the wizard to add a new
record, when I click on it, it clears the screen to start
a new record but the cursor is missing.
When I use the Add New Record button on the bottom of the
screen where the record counter is, it clears the screen
and puts the cursor where it belongs on the first field.

Does anyone have an idea on how to make the button I
designed through the wizard put the cursor where it
belongs.

Thanks
Al
 
A

alan

try putting "me.YourTextField.SetFocus" as the last
command line of the on click event of the buton. Replace
YourTextField with the object you want the cursor to go to.
 
R

Randy Wayne

If you are comfortable with VBA coding do the following.

Open the form is design mode.
Select the command button you created to add record.
With the properties sheet open select the EVENT tab.
The On Click procedure should say [Event Procedure].
Click it once and you should see an arrow and ...
Click the ... buton, this will open up the VBA editor.

You will see something like this:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

DoCmd.GoToRecord , , acNewRec

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Add the following line of code directly below the
DoCmd.GoToRecord , , acNewRec

YourControlName.SetFocus

Instead of YourControlName use the name of the control
(text box) that you want to have the focus. For example,
if your text box is called FirstName than it would be:

FirstName.SetFocus

The whole thing would look like:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

DoCmd.GoToRecord , , acNewRec
FirstName.SetFocus

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Let me know if this helps.
 
G

Guest

Worked great.. Thanks... this will go on my catalog of
solutions.
-----Original Message-----
If you are comfortable with VBA coding do the following.

Open the form is design mode.
Select the command button you created to add record.
With the properties sheet open select the EVENT tab.
The On Click procedure should say [Event Procedure].
Click it once and you should see an arrow and ...
Click the ... buton, this will open up the VBA editor.

You will see something like this:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

DoCmd.GoToRecord , , acNewRec

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Add the following line of code directly below the
DoCmd.GoToRecord , , acNewRec

YourControlName.SetFocus

Instead of YourControlName use the name of the control
(text box) that you want to have the focus. For example,
if your text box is called FirstName than it would be:

FirstName.SetFocus

The whole thing would look like:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

DoCmd.GoToRecord , , acNewRec
FirstName.SetFocus

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Let me know if this helps.




-----Original Message-----
If I put a button on a form, using the wizard to add a new
record, when I click on it, it clears the screen to start
a new record but the cursor is missing.
When I use the Add New Record button on the bottom of the
screen where the record counter is, it clears the screen
and puts the cursor where it belongs on the first field.

Does anyone have an idea on how to make the button I
designed through the wizard put the cursor where it
belongs.

Thanks
Al
.
.
 

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