Cursor will not start in first field box

G

Guest

I put an 'add new record' button on my forms. When I click it to add new
data, I also have to click in the first field to begin. Why won't the cursor
automatically appear in the first field after the 'add new record' button is
clicked?
 
B

Bob Howard

You need to put a setfocus method in the onclick event to move the focus off
the button you just clicked and onto the data field. Access only moves the
focus when either the user clicks on something or the program moves it.
 
J

Jeff Conrad

in message:
I put an 'add new record' button on my forms. When I click it to add new
data, I also have to click in the first field to begin. Why won't the cursor
automatically appear in the first field after the 'add new record' button is
clicked?

On the Current event of the form, test to see if you are on a new record.
If you are, set the focus to whatever control you wish. Something like so:

Private Sub Form_Current()
If Me.NewRecord = True Then
Me.MyFirstControlNameHere.SetFocus
End If
End Sub
 
G

Guest

Thank you. Please tell me how to do this as I am not advanced enough to know
what you are talking about. Be explicit with instructions.
 
G

Guest

Thank you. Please give more explicit instructions as I am a novice to
Access. "On the Current event of the form, test to see if you are on a new
record." Tell me how to do this.
 
J

Jeff Conrad

in message:
Thank you. Please give more explicit instructions as I am a novice to
Access. "On the Current event of the form, test to see if you are on a new
record." Tell me how to do this.

1. Open the form in Design View

2. On the main menu bar go to View | Properties.
This will bring up the form's properties list.
(The dialog box should say "Form" in the upper left corner)

3. On the "All" or "Event" tabs look for an line that says
"On Current"

4. Single click on that line itself and a little arrow will appear at
the right side of this line along with a little button that has three
dots on it (...). Click that button with the three dots and a small
dialog prompt will appear. Select the option that says "Code
Builder" and click OK to go to the code window for this form.

5. Your cursor should be in between these two lines:

Private Sub Form_Current()

End Sub

6. Copy and paste this code *in between* those two lines:

If Me.NewRecord = True Then
Me.MyFirstControlNameHere.SetFocus
End If

7. Now where I have the long word MyFirstControlNameHere
you will need to *replace* that part with the actual name of the
form control you want the cursor to be on for a new record. So
if, for example your first form control is called FirstField change the
code to this:

If Me.NewRecord = True Then
Me.FirstField.SetFocus
End If

Follow me?

8. Compile the code (Debug | Compile from menu bar here)

9. Save and close the form and then test. That's it.

--
Jeff Conrad
Access Junkie
Bend, Oregon


 

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