I'm having problem saving a new record from a form without closing it and open a report. Please help.
When the main form and it's subform is opened, an auto-numbered field is populated. Once the main and sub form is completely filled, a command button needs to save the record and before closing it open a report preview using that auto-numbered field. I've tried several methods to save the record when the command button is pressed but none works. The error in all methods is Syntax error (missing operator) in query expression 'AutoGeneratedID='. But it works if I close the form and reopen the form filled with that record.
When the main form and it's subform is opened, an auto-numbered field is populated. Once the main and sub form is completely filled, a command button needs to save the record and before closing it open a report preview using that auto-numbered field. I've tried several methods to save the record when the command button is pressed but none works. The error in all methods is Syntax error (missing operator) in query expression 'AutoGeneratedID='. But it works if I close the form and reopen the form filled with that record.
Code:
Me.Dirty = False
Forms![frm_AddNewRecord]![Firstname].SetFocus
DoCmd.RunCommand acCmdSaveRecord
Form_frm_AddNewRecord.Requery
Form_frm_AddNewRecord.Refresh
...
...
DoCmd.OpenReport MyReport, acPreview, , "AutoGeneratedID=" & AutoGeneratedID