none
Save a Record using a form and Automate Printing a report based on the record RRS feed

  • Question

  • Before leaving my data entry screen, i want to print a report based on the data.

    Data is entered.  A command button is used to save the data and open the report.  Once the report is printed, the report should close and the data entry form should close, or go to a new record - depending on the button used. (both codes on the last line)

    DoCmd.Save

    DoCmd.OpenReport "rptWRS", acViewReport, , "RequestNo =" & txtRequestNo

    DoCmd.RunCommand acCmdPrint

    DoCmd.Close

    DoCmd.Close  OR   DoCmd.GoToRecord, "frm_Data_Entry", acNewRec

    This worked for me the first two times, and then it stopped working.  No other parameters were changed. 

    Thanks for any insight you can offer.


    MS - Teach me to fish

    Tuesday, April 26, 2016 7:48 PM

Answers

  • Hi. First of all, DoCmd.Save doesn't save the record as you were expecting. Rather, it's saving any design changes to the form. Also, the acViewReport argument of the OpenReport method only opens the report for viewing rather than printing. If you don't care to see the report and just have it go straight to the printer, try using the acViewNormal argument or just delete the argument because it will default to sending the report to the printer. So, for example, try:

    DoCmd.RunCommand acCmdSaveRecord

    DoCmd.OpenReport "rptWRS", , , "RequestNo=" & Me.txtRequestNo

    DoCmd.GoToRecord , , acNewRec

    Hope that helps...

    • Marked as answer by lismeta Tuesday, April 26, 2016 8:35 PM
    Tuesday, April 26, 2016 8:13 PM

All replies

  • Hi. First of all, DoCmd.Save doesn't save the record as you were expecting. Rather, it's saving any design changes to the form. Also, the acViewReport argument of the OpenReport method only opens the report for viewing rather than printing. If you don't care to see the report and just have it go straight to the printer, try using the acViewNormal argument or just delete the argument because it will default to sending the report to the printer. So, for example, try:

    DoCmd.RunCommand acCmdSaveRecord

    DoCmd.OpenReport "rptWRS", , , "RequestNo=" & Me.txtRequestNo

    DoCmd.GoToRecord , , acNewRec

    Hope that helps...

    • Marked as answer by lismeta Tuesday, April 26, 2016 8:35 PM
    Tuesday, April 26, 2016 8:13 PM
  • Thanks DB Guy!  That did exactly what I was looking for.

    Thanks for the tip on DoCmd.Save as well!


    MS - Teach me to fish

    Tuesday, April 26, 2016 8:36 PM
  • Hi. You're welcome. Glad we could assist. Good luck with your project.
    Tuesday, April 26, 2016 8:49 PM