Solved

How can I specify a network printer with VBA code?

Posted on 2001-07-27
8
381 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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