Difference between Macro and code

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Back
Top