Need Help Selecting Printer & Print Qty From Code

threeo2

Registered User.
Local time
Today, 20:30
Joined
Feb 11, 2003
Messages
31
Is it possible to specify the printed to be used and number of copies to be printed from a report with code? I have a form I use to view product info like product ID, description, price, quantity in stock, etc. I have a button that prints a report generating my product label to a label printer. I need to be able to specify which printer it goes to depending on the user, as well as how many labels to print. Anyone know how to do this?

Thanks, Threeo2
 
In Access 2002 it's relatively easy. I've never succeeded in earlier versions. If you have 2002 look in help for the Printers Collection
Keith
 
Print dialogue box

To show the Print dialogue box to allow you to select the printer you wish to print to do the following:


Set the code on the command button to docmd.openreport “ReportName”,acviewprintpreview


Add the following to the "On Activate" event of the report.

Private Sub Report_Activate()
On Error GoTo Err_Report_Activate

If Me.Report.HasData Then
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, Me.Name

Else
MsgBox "There is no data for this report. Canceling report...", vbInformation
DoCmd.Close acReport, Me.Name

End If

Err_Report_Activate:
Resume Next
DoCmd.Close acReport, Me.Name

End sub

Not sure about specifying a printer and no of copies in code but the above may help.

Dave
 
Last edited:
Thanks for the suggestions guys. What i need to do however is just have that report print to a specific printer & quantity set by the code. I don't want the user to do it. Here's what I have now to specify the qty. It works fine but you see the form open for a split seccond and the whole process is kinda slow. I want to find better, more professional way to do it.

Dim StrPQ As Integer

StrPQ = [ProductQty]

DoCmd.OpenReport "M40-Label", acViewPreview, "", "", acNormal
DoCmd.PrintOut acSelection, , , acHigh, StrPQ, True
DoCmd.Close acReport, "M40-Label"

I tried to open the report in the hidden view but the printout cmd then prints the form on top.
 
I am starting up an online coffee shop and I am thinking about printing my own labels due to the variety that I will be needing. I am looking at these printers Primera LX400 Label Inkjet Printer or Primera LX900 Label Inkjet Printer and wondered if anyone has any experience with them or suggestions of others for me to consider. Thanks for your help,
If you want to select an open report and print it with a particular printer then you might try this code AFTER you open the report:
Code:
Dim PrtLoop As Printer
Dim SelectedPrinter As String
For Each PrtLoop In Application.Printers
    With PrtLoop
    If .DeviceName Like "Primera LX400*" Then
       SelectedPrinter = .DeviceName
       Set Application.Printer = Application.Printers(SelectedPrinter)
       DoCmd.SelectObject acReport, Screen.ActiveReport.Name
       DoCmd.PrintOut acPrintAll, , , acHigh, 1
    End If
    End With
Next PrtLoop
Code:
You need to:
  1. Go through your installed printers
  2. Select the one you want (in this case a Primera LX400)
  3. Set the Application.Printer to the Primera (SelectedPrinter)
  4. Select the report itself
  5. Print it with the new Application printer
Of course you change the device name as needed. This should not change the Default printer setting. It should only use the selected printer to print the selected report.
 

Users who are viewing this thread

Back
Top Bottom