On Click - open to new record

G

Guest

What do I need to add to my button On Click so that the form will open to a
new record?

Private Sub OpenComplaints_Click()
On Error GoTo Err_OpenComplaints_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmComplaints"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OpenComplaints_Click:
Exit Sub

Err_OpenComplaints_Click:
MsgBox Err.Description
Resume Exit_OpenComplaints_Click

End Sub

THANKS!
 
G

Guest

Private Sub OpenComplaints_Click()
On Error GoTo Err_OpenComplaints_Click

DoCmd.GoToRecord acDataForm, Me.Name, acNewRec

Exit_OpenComplaints_Click:
Exit Sub

Err_OpenComplaints_Click:
MsgBox Err.Description
Resume Exit_OpenComplaints_Click

End Sub
 
G

Guest

Oops! Disregard my last post. I wasn't paying close enough attention.
If the form is going to always be opened to a new record, you can just set
the form's Data Entry property to True. If you are going to want to be able
to edit existing records as well as enter new records, you will have to tell
the form to open to a new record when you open it. You can do that by using
the OpenArgs argument of the OpenForm method. You also have to look for the
value in the Load event of the form you are opening.

DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "New"

Then in the Load event of the form you are opening:

If Me.OpenArgs = "New" Then
DoCmd.GoToRecord adDataForm, Me.Name, acNewRec
End If
 
G

Guest

Thanks, Klatuu.

I'm not sure I follow this. The code doesn't reference "frmComplaints" and
therefore doesn't open it.

What am I not seeing?
 
G

Guest

I know, this was not the correct answer, I did send a follow up that should
correct the problem.
 
G

Guest

Thanks. I've set it up to open to a new record and add/edit records but when
I click the button I get an error: The object 'frmComplaints' isn't open.
 
G

Guest

Klatuu said:
Post back with the code as it is now, please.

Button:
Private Sub OpenComplaints_Click()
On Error GoTo Err_OpenComplaints_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmComplaints"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "New"

Exit_OpenComplaints_Click:
Exit Sub

Err_OpenComplaints_Click:
MsgBox Err.Description
Resume Exit_OpenComplaints_Click

End Sub

Form:
Private Sub Form_Load()
If Me.OpenArgs = "New" Then
DoCmd.GoToRecord adDataForm, Me.Name, acNewRec
End If

End Sub
 
G

Guest

My typo
adDataForm should be acDataForm
I can't be sure that is the problem, but try that.
This is in the Load event of the form frmComplaints, right?
 

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