Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I specify a network printer with VBA code?

Posted on 2001-07-27
8
Medium Priority
?
458 Views
Last Modified: 2012-05-04
Hi,

I'm using Access 97 on a Windows NT 4 network.
I want to print a report from code to a network printer that is not the Windows default printer. How can I do this?

Thanks for your help.
0
Comment
Question by:Minuteman
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Accepted Solution

by:
mlcktmguy earned 600 total points
ID: 6326447
Minuteman,
If you always want this report to go to the same printer every time it is run you don't even have to use code.  You can accomplish that in the report designer.  While editing the report click 'File' then 'Page Setup' then the 'Page' tab then 'Use specific printer' then the 'Printer' button.  At this point you will be able to select the specific printer that you want the report to route to.  Click OK all of the way out and save the report.  It will always go to the same printer no matter who runs it.

I don't know how to accomplish this in code but I would guess that it is possible.  If that is your goal I'm sure that someone will have a code based solution for you.

Good Luck
0
 
LVL 3

Expert Comment

by:carruina
ID: 6326448
Insert in a form a control MS Common Dialog named "Dialog"

and try with this code:

the line "Dialog.Object.ShowPrinter " shows a forms with all the printers instaled in the system and you con select the network printer.



Private Sub Comando0_Click()

Dialog.Object.ShowPrinter

DoCmd.OpenReport ("Report")
End Sub
0
 
LVL 58
ID: 6326545
Your best bet is to buy some code in one form or another.  With A97, you need to deal with the PRTMip and PRTDev data structures.  This is what Access stores with a report to determine the printer being used.

 One source of the code is the Access 97 Developers Handbook published by Sybex.  Contains many print routines that you can use to control printers.

 Another (and the one I use), is a product called "On The Fly Printing" by ATTAC consulting.  Does everything you need to do and is a drop in.  You can check it out on their web site:

http://ourworld.compuserve.com/homepages/attac-cg/

  They have been offering this since version 2 and it's very stable code.  Price is quite resonable as well.

Jim.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Minuteman
ID: 6326614
mlcktmguy,
I didn't know you could set a specific printer for individual forms and reports. That helps. However, I still want to do it through code, because I don't want the report printed to the same printer each time.

carruina,
I can't use a dialog because of the specific situation I have: the application has 2 modes, interactive and batch. In interactive mode, I want to print to the default printer. In batch mode, I want to print to a specific network printer.

Jim,
I was hoping there was some easy way to do this, like setting the PrtDevMode property to a certain value. I'm not willing to pay for the solution (other then with EE points :o).

While writing this I just thought of a workaround: I could create 2 copies of the report, one with a specific printer specified (using mlcktmguy's method), and one for the default printer. It's not the most elegant solution, but it'll work.

If there's no easy solution with code, I'll go for this, and award the points to mlcktmguy with a grade of B.

Minuteman
0
 
LVL 58
ID: 6326659
Minuteman,

<<I was hoping there was some easy way to do this, like setting the PrtDevMode property to a certain value.
I'm not willing to pay for the solution (other then with EE points :o).>>

  Dealing with the PrtDevMode and PrtMip properties of the report are not a trival task as it is tied into many calls of the Windows API.  I would strongly suggest getting the code in one form or another.  The book I mentioned costs $49 US and is well worth it for that alone (besides the ton of other stuff you get).

  OTF printing cost $100 US, and grants you the license to distribute royalty free.

  In either case, the cost of purchasing them is very small as compared to the cost of developing the routines on your own.

<<While writing this I just thought of a workaround: I could create 2 copies of the report, one with a
specific printer specified (using mlcktmguy's method), and one for the default printer. It's not the
most elegant solution, but it'll work.>>

  Yes, that would work, but you now have the added over head of maintaing two reports.  Also, the printer needs to be mapped in exactly the same way on every client.  If it's not, they'll get a dialog that the printer is no longer avilable and will be switched to the default printer.

<<If there's no easy solution with code, I'll go for this, and award the points to mlcktmguy with a grade
of B.>>

  There is a code solution, but I would not call it easy. Here is a link to a site where you can find references to the code online:

http://www.mvps.org/access/reports/rpt0009.htm

Jim.
0
 
LVL 1

Author Comment

by:Minuteman
ID: 6326821
Jim,
Thanks for the extra info, but for now I'll just go with quick and dirty if it's all the same to you. (And also if it isn't ;^)

Erik
0
 
LVL 3

Expert Comment

by:carruina
ID: 6326998
How launch the batch process.

Wath about to select the printer previous this code
for example

Public Sub

...

Dim Dialog As New MSComDlg.CommonDialog
Dialog.ShowPrinter


ExecBatch

end sub

You don't need a form to use this object by this way
0
 
LVL 1

Author Comment

by:Minuteman
ID: 6327157
Carruina,
My batch process is completely automated. It is started automatically by a Scheduler application, and I can't have a dialog popping up waiting to be answered.

Erik
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

927 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