Where to add code to open form

C

CW

I want a form to open in Add mode. I understand that I need to add acFormAdd
but I'm not sure whereabouts it should go in the existing command button code
- I've tried several places but without success - advice needed please!
Below is my existing code - where should I put acFormAdd?
Many thanks
CW

Private Sub cmdInvHeaderForm_Click()
On Error GoTo Err_cmdInvHeaderForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInvoiceHeader"

stLinkCriteria = "[Ref]=" & Me![Ref]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!frmInvoiceHeader.Ref = Forms!Main.Ref

Exit_cmdInvHeaderForm_Click:
Exit Sub

Err_cmdInvHeaderForm_Click:
MsgBox Err.Description
Resume Exit_cmdInvHeaderForm_Click

End Sub
 
R

Rick Brandt

CW said:
I want a form to open in Add mode. I understand that I need to add
acFormAdd but I'm not sure whereabouts it should go in the existing
command button code - I've tried several places but without success -
advice needed please! Below is my existing code - where should I put
acFormAdd?
Many thanks
CW

Private Sub cmdInvHeaderForm_Click()
On Error GoTo Err_cmdInvHeaderForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInvoiceHeader"

stLinkCriteria = "[Ref]=" & Me![Ref]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!frmInvoiceHeader.Ref = Forms!Main.Ref

Exit_cmdInvHeaderForm_Click:
Exit Sub

Err_cmdInvHeaderForm_Click:
MsgBox Err.Description
Resume Exit_cmdInvHeaderForm_Click

End Sub

Replace...

DoCmd.OpenForm stDocName, , , stLinkCriteria

....with...

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
 
C

CW

Perfect - I really appreciate the quick response, too
Thanks Rick
CW

Rick Brandt said:
CW said:
I want a form to open in Add mode. I understand that I need to add
acFormAdd but I'm not sure whereabouts it should go in the existing
command button code - I've tried several places but without success -
advice needed please! Below is my existing code - where should I put
acFormAdd?
Many thanks
CW

Private Sub cmdInvHeaderForm_Click()
On Error GoTo Err_cmdInvHeaderForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInvoiceHeader"

stLinkCriteria = "[Ref]=" & Me![Ref]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!frmInvoiceHeader.Ref = Forms!Main.Ref

Exit_cmdInvHeaderForm_Click:
Exit Sub

Err_cmdInvHeaderForm_Click:
MsgBox Err.Description
Resume Exit_cmdInvHeaderForm_Click

End Sub

Replace...

DoCmd.OpenForm stDocName, , , stLinkCriteria

....with...

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
 

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