J
Janis
I have a printer function to cycle through network numbers 1-9 because the
networks are assigned dynamically. I'm trying to debug it since it stops on
the i = 1 and doesn't loop. I know the current network number is 2.
Public Function getPrinter(ByRef nError As Long)
Dim i As Integer
On Error Resume Next
For i = 1 To 9
Err.Clear
Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on Ne0" &
i & ":"
If Err.Number = 0 Then
getPrinter = i
Else
MsgBox "Network Printer" & " " & i
Exit For
End If
Next
nError = Err.Number <> 0
MsgBox "There was a printer error" & " " & Err.Number
End Function
I thought it might be the scope of the variable but I have a module level
variable for the nError and nPrinter.
Private nNetwork As Integer 'for printer function
Private nError As Long 'forprinter function
It is weird when I step through it. It goes to the else so that means there
isn't an error/ Then I get the printer number 1 in the first msgbox. Then
nError gets set to -1 in the quick watch, then I get another msgBox that the
error is 1004? I can't really tell where the error lies.
----code in sub procedure to call print string-----------
nNetwork = getPrinter(nError)
If nNetwork = 0 Then
MsgBox "the command to print has an error."
MsgBox nError
Else
Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on
Ne0" & nNetwork & ":"
MsgBox nNetwork
End If
networks are assigned dynamically. I'm trying to debug it since it stops on
the i = 1 and doesn't loop. I know the current network number is 2.
Public Function getPrinter(ByRef nError As Long)
Dim i As Integer
On Error Resume Next
For i = 1 To 9
Err.Clear
Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on Ne0" &
i & ":"
If Err.Number = 0 Then
getPrinter = i
Else
MsgBox "Network Printer" & " " & i
Exit For
End If
Next
nError = Err.Number <> 0
MsgBox "There was a printer error" & " " & Err.Number
End Function
I thought it might be the scope of the variable but I have a module level
variable for the nError and nPrinter.
Private nNetwork As Integer 'for printer function
Private nError As Long 'forprinter function
It is weird when I step through it. It goes to the else so that means there
isn't an error/ Then I get the printer number 1 in the first msgbox. Then
nError gets set to -1 in the quick watch, then I get another msgBox that the
error is 1004? I can't really tell where the error lies.
----code in sub procedure to call print string-----------
nNetwork = getPrinter(nError)
If nNetwork = 0 Then
MsgBox "the command to print has an error."
MsgBox nError
Else
Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on
Ne0" & nNetwork & ":"
MsgBox nNetwork
End If