Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer setting to max copies

Status
Not open for further replies.

dedo8816

Programmer
Oct 25, 2006
94
GB
Hi,

I have a label printing program which as a novice has taken me a while to build but works like a dream at the moment. I often however find that when someone wants to print say 4 labels, they click into the commondialog copies and change the 1 to 4 (all is good), but a lot of times they dont pay attention to what they type and they actually add the 4 infront of or behind the 1. They press enter or return and whoops, out pops 14 or 41 labels.

Ive tried to write this code into the print button on the program but it doesnt seem to have the desired effect.

Dim ExceedMaxPrint
If CommonDialog1.Copies > 10 Then
ExceedMaxPrint = MsgBox("You are about to print 10 or more copies, do you want to continue?", 36)
If ExceedMaxPrint = 6 Then
Printer.EndDoc
Else: Exit Sub
End If
End If

What im trying here is to tell the user they are trying to print more that 10 labels, and then give them the choice of continuing the print or cancelling it so they can review the quantity.

I dont know if its needed but the entire code behind the print button is:

Private Sub cmdprint_Click()

If Chkopenwrite.Value = 1 Then
frmprnprev.lblPartN.Caption = frmfind.txtpartno.Text
frmprnprev.LblpartnoBrc.Caption = frmfind.txtpartno.Text
frmprnprev.lblPRN.Caption = frmfind.TxtLotR.Text
frmprnprev.lblprbarc.Caption = frmfind.TxtLotR.Text
frmprnprev.LblLocBrc.Caption = frmfind.txtloc.Text
frmprnprev.lblLoc.Caption = frmfind.txtloc.Text
frmprnprev.LblRevbrc.Caption = frmfind.txtrev.Text
frmprnprev.lvlRev.Caption = frmfind.txtrev.Text
frmprnprev1.lblPartN.Caption = frmfind.txtpartno.Text
frmprnprev1.LblpartnoBrc.Caption = frmfind.txtpartno.Text
frmprnprev1.lblPRN.Caption = frmfind.TxtLotR.Text
frmprnprev1.lblprbarc.Caption = frmfind.TxtLotR.Text
frmprnprev1.LblLocBrc.Caption = frmfind.txtloc.Text
frmprnprev1.lblLoc.Caption = frmfind.txtloc.Text
frmprnprev1.LblRevbrc.Caption = frmfind.txtrev.Text
frmprnprev1.lvlRev.Caption = frmfind.txtrev.Text
ElseIf Chkopenwrite.Value = 0 Then
frmprnprev.lblPartN.Caption = frmfind.lblPartN.Caption
frmprnprev.LblpartnoBrc.Caption = frmfind.lblPartN.Caption
frmprnprev.lblprbarc.Caption = frmfind.TxtLotR.Text
frmprnprev.lblPRN.Caption = frmfind.TxtLotR.Text
frmprnprev.LblLocBrc.Caption = frmfind.lblLoc.Caption
frmprnprev.lblLoc.Caption = frmfind.lblLoc.Caption
frmprnprev.LblRevbrc.Caption = frmfind.lblrev1.Caption
frmprnprev.lvlRev.Caption = frmfind.lblrev1.Caption
frmprnprev1.lblPartN.Caption = frmfind.lblPartN.Caption
frmprnprev1.LblpartnoBrc.Caption = frmfind.lblPartN.Caption
frmprnprev1.lblprbarc.Caption = frmfind.TxtLotR.Text
frmprnprev1.lblPRN.Caption = frmfind.TxtLotR.Text
frmprnprev1.LblLocBrc.Caption = frmfind.lblLoc.Caption
frmprnprev1.lblLoc.Caption = frmfind.lblLoc.Caption
frmprnprev1.LblRevbrc.Caption = frmfind.lblrev1.Caption
frmprnprev1.lvlRev.Caption = frmfind.lblrev1.Caption
End If

frmprnprev.lblQTY.Caption = frmfind.TxtQTY.Text
frmprnprev.LblqtyBrc.Caption = frmfind.TxtQTY.Text
frmprnprev.LblFor.Caption = frmfind.TxtFor.Text
frmprnprev.lbltime.Caption = frmfind.lbltime.Caption
frmprnprev1.lblQTY.Caption = frmfind.TxtQTY.Text
frmprnprev1.LblqtyBrc.Caption = frmfind.TxtQTY.Text
frmprnprev1.LblFor.Caption = frmfind.TxtFor.Text
frmprnprev1.lbltime.Caption = frmfind.lbltime.Caption

CommonDialog1.DialogTitle = "RTA Label Printer"
CommonDialog1.CancelError = True
CommonDialog1.PrinterDefault = False

On Error Resume Next

CommonDialog1.ShowPrinter

If Err Then
MsgBox "Print Cancelled"
Exit Sub
End If
Printer.ScaleMode = 6
Printer.FontSize = 8
Printer.CurrentY = Printer.CurrentY + 180

Printer.Copies = CommonDialog1.Copies

If FrmDB.Combo1.Text = "Zebra / Datamax" Then
frmprnprev1.PrintForm
End If

If FrmDB.Combo1.Text = "Dymo Label Writer" Then
frmprnprev.PrintForm
End If

Dim ExceedMaxPrint
If CommonDialog1.Copies > 10 Then
ExceedMaxPrint = MsgBox("You are about to print 10 or more copies, do you want to continue?", vbYesNo)
If ExceedMaxPrint = vbYes Then
Printer.EndDoc
Else: Exit Sub
End If
End If

TxtSearch.SetFocus

Dim reply
reply = MsgBox("Would you like to clear all fields?", 36)
If reply = 6 Then
TxtSearch.Text = ""
TxtFor.Text = ""
TxtQTY.Text = ""
TxtLotR.Text = ""
txtpartno.Text = ""
txtloc.Text = ""
txtrev.Text = ""
DataEnvironment1.rsCommand1.MoveFirst
TxtSearch.SetFocus
CmdPrint.Default = False
CmdSearch.Default = True
CommonDialog1.Copies = 1
Else: CommonDialog1.Copies = 1
End If

End Sub

The label being printed is just set up on a standard form. The information being typed on one form is copied to another and the results printed.

If anyone can advise, that would be greatly appreciated.

Thanks
D
 
I think that you need to check on the copies parameter before you send anything to the printer. Your code has already buffered data to the printer (including the number of copies). Something like
Code:
[blue]... Preceding Code ...[/blue]
Dim nCopies As Long
CommonDialog1.ShowPrinter

If Err Then
    MsgBox "Print Cancelled"
    Exit Sub
End If

nCopies = CommonDialog1.Copies 
If nCopies > 10 Then
    If MsgBox("You are about to print " & nCopies & " " & vbCrLf & _
              "Do you want to continue?", vbQuestion + vbYesNo) = vbNo Then
        Exit Sub
    End If
End If

Printer.ScaleMode = 6
Printer.FontSize = 8
Printer.CurrentY = Printer.CurrentY + 180
Printer.Copies = nCopies 

If FrmDB.Combo1.Text = "Zebra / Datamax" Then
    frmprnprev1.PrintForm
End If

If FrmDB.Combo1.Text = "Dymo Label Writer" Then
    frmprnprev.PrintForm
End If

Printer.EndDoc

TxtSearch.SetFocus
[blue]... Following Code ...[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top