Command button code not working

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi
Colleague trying to use a command button on a data entry
form Code attached to button is is:
Private Sub Command353_Click()
DoCmd.Save
DoCmd.OpenReport "MyReport",
acViewPreview, , "[FFFFOwner] = '" & Me!
[FFFFOwner] & "'"
DoCmd.PrintOut
End Sub
Message window has wrapped line of code
The action is meant to save the entry in the form and
print the report. However it is not saving the entry just
printing the report. Any ideas what is going wrong here?
Thanks
 
Hi
Colleague trying to use a command button on a data entry
form Code attached to button is is:
Private Sub Command353_Click()
DoCmd.Save
DoCmd.OpenReport "MyReport",
acViewPreview, , "[FFFFOwner] = '" & Me!
[FFFFOwner] & "'"
DoCmd.PrintOut
End Sub
Message window has wrapped line of code
The action is meant to save the entry in the form and
print the report. However it is not saving the entry just
printing the report. Any ideas what is going wrong here?
Thanks

DoCmd.Save does not save the latest record, it saves changes made to
the Form Object itself.
See VBA Help on the Save Action.

Use:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport etc. .....
 
Hi
Colleague trying to use a command button on a data entry
form Code attached to button is is:
Private Sub Command353_Click()
DoCmd.Save
DoCmd.OpenReport "MyReport",
acViewPreview, , "[FFFFOwner] = '" & Me!
[FFFFOwner] & "'"
DoCmd.PrintOut
End Sub
Message window has wrapped line of code
The action is meant to save the entry in the form and
print the report. However it is not saving the entry just
printing the report. Any ideas what is going wrong here?
Thanks

DoCmd.Save does not save the latest record, it saves changes made to
the Form Object itself.
See VBA Help on the Save Action.

Use:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport etc. .....

I should have added to my previous post that if you wish to print the
report, simply omit the acViewPreview (but leave the comma) and the
report will print without preview and without the need for the
DoCmd.PrintOut line.

Private Sub Command353_Click()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "MyReport", , , "[FFFFOwner] = '" & Me!
[FFFFOwner] & "'"

End Sub
 
Back
Top