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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wiswalldCommented:
Private Sub Command25_Click()
Forms!formname.ticket = me.ticket
        DoCmd.OpenForm "frmServiceTicketEvents", acNormal, , acnewrec
End Sub
0
wiswalldCommented:
Sorry should be


Private Sub Command25_Click()
        DoCmd.OpenForm "frmServiceTicketEvents", acNormal, , acnewrec
Forms!formname.ticket = me.ticket
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.