Changing Printers using code...

  • Thread starter Thread starter sjmooreevolutionltd
  • Start date Start date
S

sjmooreevolutionltd

Guest
Can anyone help me with this? Need to be able to select printers for specific reports using code. Is it just the PrtDevMode that handles this? If so can anyone expand on it's usage? Maybe someone out there has got some existing code that does this that they wouldn't mind sharing?
 
Hi everyone

I too would appreciate some code that did this. I would like to be able, on specific reports, to change from the default printer to a pdf writer and then back to the default printer (when the report closes). I have seen some code that goes someway to doing this ... but it does not return the printer settings to the default printer on exit.

At the moment I can't find a copy of this coding (it's at home on an earlier version of the database that I use at work).

Thanks

Rich Gorvin

[This message has been edited by Rich@ITTC (edited 04-19-2001).]
 
I have a working sample of using the Common Dialogue to do this. Email me if you are interested.

DES
 
If you are sending your reports directly to the printer, here is a way to get the Print Dialog Box to show so you can choose the printer settings. You will notice that the report is opened acPreview but don't worry, it will not become visible on screen. Just follow the instructions.

Use DoCmd.OpenReport method to open the report:

DoCmd.OpenReport "YourReportNameHere", acViewPreview

Now open the Report in design view. Use the following code in the On Activate event of the Report:

Private Sub Report_Activate()
Dim strMsg As String, strTitle As String
strMsg = "There Were No Records Returned for Criteria Entered."
strTitle = " No Matching Records"

On Error Resume Next

If Me.HasData Then
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, Me.Name
Else
MsgBox strMsg, vbInformation + vbOKOnly, strTitle
DoCmd.Close acReport, Me.Name
End If
End Sub

The above code also handles the problem if there are no records returned by recordset. So you don't have to use the On No Data event.

The code will cause the Print Dialog Box to open so you can change the print settings, then print the report, close the report, without it ever becoming visible on screen.

HTH
RDH
 
Hi Des and R Hicks

Thank you both for providing your examples. They both do similar things, from what I can see, in that they bring up the Windows Print Common Dialoge Box and allow the user to change the printer.

Des, your example works very well - thanks for that as I have tried it out just now. Thank you for e-mailing your demo.

R Hicks, I haven't tried yours because it appears from the coding to open the Print options ... but what I really wanted was something that would make the actual change of printer automatically.

My challenge for the forum is this - I want to have the choice of clicking one command button for an invoice to be printed using the normal default printer, but also have an alternative command button to print the same invoice to a pdf file using the Acrobat pdf writer. This button needs to change the Default printer temporarily over to the PDF writer, print the report to file (as an attachment for an e-mail) and then re-set the printer default back to the Default network printer. I do not want users going into the Print Options dialogue box and manually making the changes (as they a) will find that confusing - believe me my staff will! and b) they probably won't remember to change back to the original default).

So has anyone else got a solution? Both Des and R Hicks have good techniques here and I am sure others will find their ideas really useful ... but neither is exactly what I ideally would like to have!

Thanks

Rich Gorvin

[This message has been edited by Rich@ITTC (edited 04-19-2001).]
 
Hi Everyone

Actually I have found that code I mentioned above in one of my posting ... it came from Dev Ashish's excellent site. Unfortunately about six months ago I tried it out and couldn't get it to work (well that isn't strictly true - it did 90% of what I wanted but it wouldn't return the printer to the original default).

So I thought I would try again as I know that Dev knows his stuff ... and it was based on code written by Ken Getz (so it really ought to work!).

Well, now it does work!

Here's the link:
http://www.mvps.org/access/reports/rpt0011.htm

There are a couple of minor errors - one module starts a function with Sub instead of Function and the final piece at the bottom of the screen needs to be like this:

ChangeToAcrobat
ChangePdfFileName "Name of pdf file including .pdf"
DoCmd.OpenReport "YourReportName", acViewNormal
ResetDefaultPrinter

So it can be done!

Rich Gorvin
 
Hi Mike

Nice one!

Actually, unfortunately I don't think it wouldn't have met my needs as much of my development work is done off-site with different printers being installed at home and at work. However, it certainly is a lot, lot less complicated!

Thanks

Rich Gorvin
 

Users who are viewing this thread

Back
Top Bottom