Use button to open form in add mode and pass number to the opening form

I have a button to  open a form in ADD mode with the argument to assign a value of the field ticket to the field ticket in the opening form. My code is as follows:

Private Sub Command25_Click()
Dim ticketnum As Integer
    ticketnum = Me.ticket
    DoCmd.OpenForm "frmServiceTicketEvents", acNormal, , , acFormAdd, , [ticket] = ticketnum
End Sub

This will open the form in ADD mode but will not populate the ticket number field.

What am I doing wrong?
Private Sub Command25_Click()
Dim ticketnum As Integer
    ticketnum = Me.ticket
    DoCmd.OpenForm "frmServiceTicketEvents", acNormal, , , acFormAdd, , [ticket] = ticketnum
End Sub

Open in new window

mflatfordAsked:
Who is Participating?
 
wiswalldConnect With a Mentor Commented:
Sorry should be


Private Sub Command25_Click()
        DoCmd.OpenForm "frmServiceTicketEvents", acNormal, , acnewrec
Forms!formname.ticket = me.ticket
End Sub
0
 
wiswalldCommented:
Private Sub Command25_Click()
Forms!formname.ticket = me.ticket
        DoCmd.OpenForm "frmServiceTicketEvents", acNormal, , acnewrec
End Sub
0
 
wiswalldCommented:
Sometimes I have a brain fart

Private Sub Command25_Click()
DoCmd.OpenForm "frmServiceTicketEvents"
docmd.gotorecord,,acnewrec
Forms!formname.ticket = me.ticket
End Sub
0
 
mflatfordAuthor Commented:
That didn't quite work but was close enough to get me there. Here is the code that works.

DoCmd.OpenForm "frmServiceTicketEvents", acNormal, , , acFormAdd
  Forms!frmServiceTicketEvents.ticket = Me.ticket

Notice the acFormAdd and there are 3 comma's.

Thanks.....Points will be awarded to you.
0
 
wiswalldCommented:
I caught myself in another post
0
All Courses

From novice to tech pro — start learning today.