?
Solved

Using Winspool.drv to print an access report

Posted on 2009-04-22
5
Medium Priority
?
535 Views
Last Modified: 2013-11-28
I would like to click a button on an Access form (Access 2003) and open the print dialog, set properties (in this case 2-sided printing) and print a report that I've passed in.  I have code that uses the winspool.drv API to open the print dialog but it doesn't print anything, just sets properties but then they don't stick if I then open the report.  Can someone tell me which winspool function I use to send the report to the printer?
0
Comment
Question by:MoonDoggie
  • 3
  • 2
5 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 2000 total points
ID: 24212117
Why not just call up the standard Print Dialog box?

This has worked fine for me for years.
;-)
Something like this:

Private Sub cmdSetPropertiesThenPrintReport_Click()

Dim strRptName As String

strRptName = "rptDetailVideos"
   
    'Turn off the screen
    DoCmd.Echo False
    'Open the report
    DoCmd.OpenReport strRptName, acViewPreview
    'Open the Print Dialog box
    DoCmd.RunCommand acCmdPrint
    'Close the report
    DoCmd.Close acReport, strRptName
    'Turn the screen back on
    DoCmd.Echo True

End Sub


Here is a sample, I am sure you can adapt this to work in your database.
;-)

JeffCoachman
EEQ-24347397Open-Print-DialgBox-.mdb
0
 
LVL 1

Author Comment

by:MoonDoggie
ID: 24216749
Thanks for the response, Jeff.  The reason I'm not using the standard dialog box is that this application is very locked down.  The way it was built is that when a report is opened, it is pop-up and modal.  Then a little form is opened pop-up on top of that.  The form has a print button and a close button on it.  If I place a button on the form to open the dialog, it will want to print the pop-up form, not the report.  I toyed with hiding the form first etc.,  but then if the user cancels out of the dialog, I don't see a way to trigger the form to unhide.  After trying different methods I decided the best way would be to use the API to open the dialog but I havent figured out how to pass it a report name to print.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24221642
MoonDoggie,

<this application is very locked down.>
You did not mention this in your original post.

<but then if the user cancels out of the dialog, I don't see a way to trigger the form to unhide. >

In my sample, the Report Prints, not the Form.
Are you saying that this was not the case when you tried it?

<After trying different methods I decided the best way would be to use the API to open the dialog >
There is a way around that without using API's, but if you have already decided on this, then there is no need to discuss it.

JeffCoachman
0
 
LVL 1

Author Comment

by:MoonDoggie
ID: 24226767
My apologies.  Your sample works.  I already have the report open when the user clicks the button for print properties, therefore when I adapted your code I didn't try to open it again, but that is the very line that makes it work.  It takes the focus off the pop-up form for the dialog box.

I was also surprised to see that with echo off the dialog appears.  I would have thought that it would not.  

Thanks for your help, Jeff.

Mike
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24229017
<I was also surprised to see that with echo off the dialog appears.  I would have thought that it would not>
Me too, but I have used this technique many times and I am just greatfull that the dialog box does appear!
;-)


Jeff
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question