Valwrie
Valwrie

Reputation: 133

Accessing Variable Declared in ThisWorkbook in a Userform Initialize Sub

I'm setting up the userform based on User input of 1 to 5, however, I can't seem to get this input into the Userform_Initialise sub.

Public TP As String 'this is in ThisWorkbook; from here

Private Sub Workbook_Open()

Dim RT As String

ReEnter:

    RT = Application.InputBox("1 - Monthly" & vbNewLine & "2 - Quarterly" & vbNewLine & "3 - Semi-Annually" & _
    vbNewLine & "4 - Semi-Annually" & vbNewLine & "5 - Others", "Type of 
    Report", "Enter Number Here", Type:=1)
    If RT >= 1 And RT <= 5 Then
        TP = Val(RT)
    Else
        MsgBox "Error", vbCritical
        GoTo ReEnter

    End If

UserForm1.Show

End Sub 'to here

'This onwards is in Userform
Private Sub Userform_Initialize()

Debug.Print TP

End Sub

How do I get the code to recognise the User Input TP in the Userform? Thanks in advance!

Upvotes: 2

Views: 46

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57683

Declare your global variable in a module

Public TP As String 'this should be in a module

or if it is declared in ThisWorkbook you must use

Debug.Print ThisWorkbook.TP

in your UserForm.

Upvotes: 2

Related Questions