OPen form to new record

G

gavin

I have a data entry form for my database and want it to open up at a new
record each time I open it. I'm sure I had an example of this filed away on
my PC somewhere but I can't find it! Can someone remind me please?



Regards,



Gavin
 
R

Rick Brandt

gavin said:
I have a data entry form for my database and want it to open up at a
new record each time I open it. I'm sure I had an example of this
filed away on my PC somewhere but I can't find it! Can someone remind
me please?

Set the DataEntry property of the form to Yes.
 
B

Brian Bastl

In addition to what Rick wrote, if you want to open it to a new record but
be able to view/edit other records through this form as opposed to using it
strictly for data entry, then you'll want a slightly different approach.

Set its DataEntry property to No.

In those instance where you want to open it in DataEntry mode, specify it in
the DoCmd statement

DoCmd.OpenForm "MyForm ,,,,acFormAdd

Otherwise, you can use the following to take you to a new record, but allow
you to view and edit existing records:

DoCmd.OpenForm "MyForm"
DoCmd.GoToRecord ,, acNewRec

Brian
 
G

gavin

Brian Bastl said:
In addition to what Rick wrote, if you want to open it to a new record but
be able to view/edit other records through this form as opposed to using it
strictly for data entry, then you'll want a slightly different approach.

Set its DataEntry property to No.

In those instance where you want to open it in DataEntry mode, specify it in
the DoCmd statement

DoCmd.OpenForm "MyForm ,,,,acFormAdd

Otherwise, you can use the following to take you to a new record, but allow
you to view and edit existing records:

DoCmd.OpenForm "MyForm"
DoCmd.GoToRecord ,, acNewRec

Brian

Hi Brian,
Thanks for the reply - I'm not very experienced with VBA - where do I put
this code?


Regards,



Gavin
 
B

Brian Bastl

1. Open form in design view
2. Right-click on its title bar
3. Select Properties to open the form's property sheet

If you only want to use the form for data entry and not for editing, then
click the "All" tab and then find the line for Data Entry. Change this from
No to Yes.

If you always want to begin at a new record but also allow existing records
to be view and edited in the same form instance, then you have two options.
******************************************
Option 1 (not always the best approach): follow steps 4 thru 10.

4. Click on the "Events" tab
5. Click on the words "On Load"
6. Directly to the right, click the down arrow and select [Event Procedure]
7. Directly to the right of that, there will be a button which looks like
[...]
8. Click it to open the vba editor
9. You'll now see some text which looks like the following:
Private Sub Form_Load()
End Sub

On a blank line between those two, you'd type:
DoCmd.GoToRecord ,, acNewRec

10. Click the "Save" button and then on the application's menu bar, go to
Debug | Compile. If you get no errors, close the editor, and then the form.
Then re-open the form normally to see if it works like you want.
****************************************

Option 2 uses a command button on another form:

Follow steps 1 - 3, but obviously opening a different form
Add a command button by clicking on the toolbox
Follow the Wizard dialogue
When finished, right click the new command button and click "Build" to open
the vba editor. On a blank line directly following "DoCmd.OpenForm .....

type: DoCmd.GoToRecord ,, acNewRec

See #10 above
*******************************************



HTH,
Brian
 
Top