Solved

How can I specify a network printer with VBA code?

Posted on 2001-07-27
8
358 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
 
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now