View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
John Wirt[_2_] John Wirt[_2_] is offline
external usenet poster
 
Posts: 6
Default Scope of variable includes all Form _and_ Code modules??

I do not think this works.

I declared the variable numPrintOrder in a module 15 (one where the variable
is used in a procedure) thusly,

Option Explicit
Public numPrintOrder as integer

----------------------------------------
The value of numPrintOrder is set from the values entered in .textboxes on
frmUserForm8.

Private Sub butPrintOK_Click()
Dim numCopiestoPrint As Integer
Dim numPagestoPrint As Integer
Dim numPrintOrder As Integer

With frmUserForm10
If txtNumCopies.Value = "0" Then
numCopiestoPrint = 1
ElseIf txtNumCopies.Value < "" Then
numCopiestoPrint = txtNumCopies.Value
Else
numCopiestoPrint = 1
End If
If txtNumPages.Value = "0" Then
numPagestoPrint = 0
ElseIf txtNumPages.Value < "" Then
numPagestoPrint = txtNumPages.Value
Else
numPagestoPrint = 0
End If
End With

numPrintOrder = 100 * numPagestoPrint + numCopiestoPrint

------------------

I tried calling frmUserForm10 from code module 15, like this:

Option Explicit
Public numPrintOrder as Integer

Public Sub PrintCurrentPage() <-----Here???
Dim strWshName As String
Dim numCopiestoPrint As Integer
Dim numPagestoPrint As Integer

frmUserForm10.Show

strWshName = ActiveSheet.name

numCopiestoPrint = numPrintOrder Mod 100
numPagestoPrint = (numPrintOrder - numCopiestoPrint) / 100
If numPagestoPrint = 0 Then numPagestoPrint = 1

ActiveSheet.PrintOut _
From:=1, To:=numPagestoPrint, _
Copies:=numCopiestoPrint

End Sub
--------------------------------------------

This did not work. After fmUserForm 10 closed, the value of numPrintOrder is
0.