Cursor after adding new record

  • Thread starter Thread starter Al V
  • Start date Start date
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
 
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.
 
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.
 
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
.
.
 
Back
Top