Difference between Macro and code

G

Guest

I have a problem with a form when opening. Normally a job form opens gives a
contractID number and then opens the parent form. If this is done in a Macro
it works, I converted the Macro to Code and it creates the record but opens
the form on the next record which is empty. The code is:
Private Sub PO_AfterUpdate()
'Createjobnew
Dim tmp As String
SendKeys "{f9}", True
DoCmd.OpenForm "parent", acNormal, "", "[id]=[Forms]![Job
No]![contractid]", acEdit, acNormal
DoCmd.RunMacro "openjobslemail", , "" 'this sends out emails
DoCmd.Close acForm, "Job No"
End Sub

Any help is appreciated.
Thanks
 
A

Allen Browne

The key issue is that you need to concatenate the value of the contractid
into the WhereCondition string:

Private Sub PO_AfterUpdate()
Me.Dirty = False 'Save the record.
DoCmd.OpenForm "parent", acNormal, , "[id]=" & Me.contractid
DoCmd.RunMacro "openjobslemail", , "" 'this sends out emails
DoCmd.Close acForm, Me.Name
End Sub

It would be good to add error handling, in case the save (first line) fails.
It could fail if a required fields is missing, for example.
 

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