By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Printing Report from a button on a Form.

P: 10
Its not that easy to me that it sounds. I am working hard to make it work.
The form name is: frmTest
Button on form: btnPrint
Name of the report: rptTest
Initially the report is not opened. I will open the report with btnPrint and keep the report hidden. Then change the record source of the report and open it again (will keep it hidden this time too becase this is the requirement of the project). Then I will bring the print dialogue of windows to select the printer and print the final report.
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnPrint_Click()
  2. Dim SqL As String
  3. SqL = "This is a large line and there's no problem with this one. "
  4. DoCmd.OpenReport "rptTest", acViewReport, , , acHidden
  5. Reports![rptTest].RecordSource = SqL
  6. DoCmd.OpenReport "rptTest", acViewPreview, , , acHidden
  7. DoCmd.RunCommand acCmdPrint
  8. End Sub
Line 7 of my code will print the form not the report. I just want to print the report and of course with the print dialog of windows to select the printer which this acCmdPrint command satisfies (This feature is important for the project). I tried to use this code before line 7 but didn't work. Because the object i.e. the report is hidden.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SelectObject acReport, Screen.ActiveReport.rptTest
Any help is much appreciated.
Thanks in advance.
Attached Images
File Type: png print_dialogue.png (10.5 KB, 178 views)
Dec 28 '17 #1

✓ answered by gnawoncents

Instead of Screen.ActiveReport.rpt, have you tried explicitly naming the report?

Expand|Select|Wrap|Line Numbers
  1. 1.DoCmd.SelectObject acReport, "rptTest"
  2.  

Share this Question
Share on Google+
2 Replies


gnawoncents
100+
P: 212
Instead of Screen.ActiveReport.rpt, have you tried explicitly naming the report?

Expand|Select|Wrap|Line Numbers
  1. 1.DoCmd.SelectObject acReport, "rptTest"
  2.  
Dec 28 '17 #2

P: 10
Thank you and sorry for replying late. I was on a vacation.

Your suggestion worked but it exposed the report. Anyway I had to write some more codes to make it invisible.

Cheers!
Jan 1 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.