19

I have a form to input records to a table. I would like it to open on an empty add (New) instead of displaying the first record of the table. To be used by a Navigation Form which opens the input form from a button.

HansUp
  • 95,961
  • 11
  • 77
  • 135
Tom Gross
  • 191
  • 1
  • 1
  • 5

3 Answers3

21

You can use acFormAdd (value = 0) as the optional DataMode argument to OpenForm. Access' help describes acFormAdd as "The user can add new records but can't edit existing records." And actually, not only does that prevent editing of existing records, they are not even displayed in the form with that option.

DoCmd.OpenForm "frmaw_save",,,,acFormAdd

If you want to always use the form that way, you can set its Data Entry property to Yes (on the Data tab of the form's property sheet).

HansUp
  • 95,961
  • 11
  • 77
  • 135
  • +1 This is probably what the OP wants and not simply moving to the New Record – Conrad Frix Feb 23 '12 at 22:08
  • is there a way to pre-fill some values for the new record? – user2395238 Sep 22 '18 at 00:07
  • 1
    See whether [TextBox.DefaultValue Property](https://learn.microsoft.com/en-us/office/vba/api/access.textbox.defaultvalue) does everything you need. If not, submit a new question with details about what you hope to accomplish. – HansUp Sep 22 '18 at 00:27
  • I've got a program that uses this command, but it still shows the first record instead of the new one. Is there another setting that might be causing this? – daniel brandstetter Dec 12 '22 at 19:54
  • Do you mean the form is closed and when you then open it with the `acFormAdd` option it displays the first existing record? I don't know how that can happen. – HansUp Dec 12 '22 at 21:32
13

In the Form_Load event use the GoToRecord Method of DoCmd and pass in acNewRec for the Offset.

Private Sub Form_Load()
   DoCmd.GoToRecord , , acNewRec
End Sub
Conrad Frix
  • 51,984
  • 12
  • 96
  • 155
  • Excellent advice. Thank you both. I am starting to get the hang of this inaccessible Access language. – Tom Gross Feb 24 '12 at 13:31
  • This allows me to navigate to previous records but open to a new record which is the most common reason the form is opened. – Sensii Miller Jan 12 '17 at 22:20
9

On the property sheet, set "Data Entry" to Yes. You can turn off navigation buttons too.

RussWill
  • 201
  • 3
  • 3