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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting printer question

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
0
0
US
OK I'm stumped.

The variables are gettng the correct values. (I think)

But is still erroring out on the Aplication.Printers(strValue) in the Select Case.

Can someone look at this and let me know what I am missing.

Code:
Private Sub Printbtn_Click()
On Error GoTo Err_Handler

Dim strCurrentForm As String
strCurrentForm = Me.Form.Name

'Get Default Printer
Dim strDefaultPrinter As String
strDefaultPrinter = Application.Printer.DeviceName

    With Me
'        .SEIprint = Now()
'        .Status_of_Activity = "Requested"
    End With
    
    Dim strWhere As String

'    If Me.Dirty Then    'Save any edits.
'        Me.Dirty = False
'    End If
    
'Set Report Printer Variables
Dim strSEIprinter As String
Dim strILDprinter As String

'Define Report Printers
strILDprinter = "NRC ILSHR3 Dell Laser Printer 5310n"
strSEIprinter = "NRC SAVE09 HP LaserJet 8150"

MsgBox "Current Form: " & strCurrentForm & "."

    Select Case UCase(strCurrentForm)
        Case UCase("Add New Case"), UCase("Special Print")
            [highlight]Set Application.Printer = Application.Printers(strILDprinter)[/highlight]
                    
            MsgBox "Current Form: " & strCurrentForm & "." & vbCrLf & _
                    "using printer " & Application.Printer.DeviceName & "."
                    
        Case UCase("UpdateActivity")
            Set Application.Printer = Application.Printers(strSEIprinter)
            
            MsgBox "Current Form: " & strCurrentForm & "." & vbCrLf & _
                    "using printer " & Application.Printer.DeviceName & "."
                    
        Case Else
            MsgBox "Could not determine printer." & vbCrLf & _
                    "Using DEFAULT printer.", vbCritical + vbDefaultButton1 + vbOKOnly, _
                        "Printer Selection"
                    
    End Select
    
    If Me.NewRecord Then 'Check there is a record to print
        MsgBox "Select a record to print"
    Else
        strWhere = "ID = " & Me.ID
        DoCmd.OpenReport "CasePrint", acViewNormal, , strWhere, acWindowNormal, Me.Name
    End If

'Reset the (original) default printer
Set Application.Printer = Application.Printers(strDefaultPrinter)

Err_Handler_Exit:
Exit Sub

Err_Handler:
 If StandardErrors(Err) = False Then
    BeepWhirl
    MsgBox Err & ": " & Err.Description
 End If
 
Resume Err_Handler_Exit

End Sub

The error is

Run-time error 5:
Invalid procedure call or Argument.


And the debugger points to this line.

Set Application.Printer = Application.Printers(strILDprinter)


Thanks

John Fuhrman
 
I am grasping at straws now and need to get this working.

ANY ideas???????

Thanks

John Fuhrman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top