LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default value doesn't get passed to a sub-routine, loop doesn't iterate

Public Function GetPrinter(ByRef nError as long)
Dim Counter As Integer
' This function loops through the number 1-9 because the _
network on the printer is not stationary _
but changes from Network 1 - 9.
On Error Resume Next
For Counter = 1 To 9
Err.Clear
Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on Ne0" &
Counter & ":"
If Err.Number = 0 Then
GetPrinter = i
Exit For
Else
MsgBox "Network Printer" & Counter
End If
Next
nError = Err.Number < 0
End Sub


And use like this

nPrinter = GetPrinter(nError)
if nPrinter = 0 Then
MsgBox "the command to print has an error."
MsgBox nError
Else
'use nPrinter
End If
End Sub
--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Janis" wrote in message
...
I have this sub called in another routine which does the page setup and
sets
the page breaks and formatting for the user to print. I took out the
code
below called setprinter and made it into a subroutine because it is
called
in other scripts. The loop doesn't seem to be working.
I tried to debug it and this is what happens: It goes through the first
loop and sets counter to 1. Then it gets a 0 error and passes 0 to the
counter variable outside this script or else it is already 0 and nothing
happens because I didn't pass it out of this subroutine.

The network number changes becuase it is not fixed but dynamic so I want
it
to loop through and get the right number. The loop should have found an
error
and gone and tried network 2.
Question 1: why doesn't it find the error and try the 2nd iteration?
Question 2: how do I pass it to the main script?
tia,

Public Sub setPrinter()
Dim Counter As Integer
' This function loops through the number 1-9 because the _
network on the printer is not stationary _
but changes from Network 1 - 9.
On Error Resume Next
For Counter = 1 To 9
Err.Clear
Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on Ne0"
&
Counter & ":"
If Err.Number = 0 Then Exit For
MsgBox "Network Printer" & Counter
Next
If Err.Number < 0 Then MsgBox "the command to print has an error."
MsgBox Err.Number
End Sub



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need error loop in pivot table routine Jeff C Excel Discussion (Misc queries) 0 May 29th 08 11:08 AM
Loop Routine in Excel David Excel Programming 3 November 7th 06 10:41 PM
Loop routine fails after 10 cycles...... Tom Excel Programming 4 January 12th 06 03:45 AM
Iterate through controls lgbjr Excel Programming 3 May 28th 05 02:09 PM
Can't iterate thru a row with For peter Excel Programming 2 January 7th 05 04:46 AM


All times are GMT +1. The time now is 07:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"