Solved

How can I specify a network printer with VBA code?

Posted on 2001-07-27
8
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

627 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