Solved

How can I specify a network printer with VBA code?

Posted on 2001-07-27
8
403 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 200 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 57
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
Technology Partners: 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 57
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

685 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