Open Form to New record

D

Dave

How can I open a form to a new record?

When I use the wizard to create a command button, I get two options, "open
to a specific record" and "open with all records."

I want the form to open with a blank record. Can I do this?
 
A

Andi Mayer

How can I open a form to a new record?

When I use the wizard to create a command button, I get two options, "open
to a specific record" and "open with all records."

I want the form to open with a blank record. Can I do this?
set DataEntry in this form to true
 
F

fredg

How can I open a form to a new record?

When I use the wizard to create a command button, I get two options, "open
to a specific record" and "open with all records."

I want the form to open with a blank record. Can I do this?

You can open the new form to only allow new record entry:
Change the OpenForm argument to:
DoCmd.OpenForm "FormName", , , , acFormAdd

If your existing code is using the stDocName variable, just
add the commas and the acFormAdd to the existing code.

Alternatively code the Open event of the newly opened form:
DoCmd.RunCommand acCmdRecordsGoToNew
or
DoCmd.GoToRecord , , acNewRec
 
D

Dave

Thanks Fred but I am still having a bit of a problem.

First off, I should have mentioned I am using Access 2000 format. Perhaps
this has some bearing on the problem.

I have a "person" form with a command button that should open a "Note" form
to add a new note record.

This is the code for the Current event of my "Note" form:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrHandler

' DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdRecordsGoToNew

Exit_ErrHandler:
Exit Sub

ErrHandler:
Debug.Print "ERROR: F_Note.Form_Open"
Debug.Print Now()
Debug.Print "Err.Number: " & Err.Number
Debug.Print "Err.Description: " & Err.Description
Debug.Print "----------------"

MsgBox "Error no: " & Err.Number & _
vbCr & "Description: " & Err.Description
Resume Exit_ErrHandler

End Sub

When I use "DoCmd.GoToRecord , , acNewRec", I get the following error:

ERROR: F_Note.Form_Open
1/9/2005 5:55:18 PM
Err.Number: 2105
Err.Description: You can't go to the specified record.
----------------

When I use "DoCmd.RunCommand acCmdRecordsGoToNew", I get the following error

ERROR: F_Note.Form_Open
1/9/2005 5:59:04 PM
Err.Number: 2455
Err.Description: You entered an expression that has an invalid reference to
the property |.
----------------


If I try to set the open command on the "Person" form with:

DoCmd.OpenForm "FormName", , , , acFormAdd

....nothing seems to happen: the "Note" form opens without error but the
focus is on the first record, not a blank "new" record.

What could I be doing wrong?
 
F

fredg

Thanks Fred but I am still having a bit of a problem.

First off, I should have mentioned I am using Access 2000 format. Perhaps
this has some bearing on the problem.
I have a "person" form with a command button that should open a "Note" form
to add a new note record.

This is the code for the Current event of my "Note" form:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrHandler

' DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdRecordsGoToNew

Exit_ErrHandler:
Exit Sub

ErrHandler:
Debug.Print "ERROR: F_Note.Form_Open"
Debug.Print Now()
Debug.Print "Err.Number: " & Err.Number
Debug.Print "Err.Description: " & Err.Description
Debug.Print "----------------"

MsgBox "Error no: " & Err.Number & _
vbCr & "Description: " & Err.Description
Resume Exit_ErrHandler

End Sub

When I use "DoCmd.GoToRecord , , acNewRec", I get the following error:

ERROR: F_Note.Form_Open
1/9/2005 5:55:18 PM
Err.Number: 2105
Err.Description: You can't go to the specified record.
----------------

When I use "DoCmd.RunCommand acCmdRecordsGoToNew", I get the following error

ERROR: F_Note.Form_Open
1/9/2005 5:59:04 PM
Err.Number: 2455
Err.Description: You entered an expression that has an invalid reference to
the property |.
----------------

Re-read my post.
I wrote that the code goes in the form's OPEN event, NOT in the
Current event which will give the error you are getting.
 
Top