View Single Post
 
Old 08-25-2021, 11:00 PM
Justice Justice is offline Windows 10 Office 2016
Novice
 
Join Date: Aug 2021
Posts: 2
Justice is on a distinguished road
Default Userform variables in another module

Hey fellow coders,

i am having a problem concerning my UserForm. I don't know what to do.

In my main module I have a procedure that does different things. It should react accordingly to which button is clicked on the userform.

What I have:

I have my userform with two buttons and the following code:

Code:
Private Sub UserForm_Initialize()
    Dim iAnswer, iA, iB As Integer
End Sub

Private Sub CommandButtonA_Click()
    iAnswer = iA
    Unload Me
End Sub

Private Sub CommandButtonB_Click()
    iAnswer = iB
    Unload Me
End Sub
And I have a module with loads of subprocedures. One of them looks like that:

Code:
Sub main()

Dim iAnswer, iA, iB As Integer

(... code ....)

If CheckUp.Installed Then

    UserForm1.Show vbModeless
    
End If

If iAnswer = iA Then
          "do this and that"
ElseIf iAnswer = iB Then
          "do this and that"
Else
          "do that"
End If

End Sub
Problem:

The Macro doesn't react to which button is clicked. It just proceeds the first if-case. I guess this is because the variables from the UserForm don't get transported over to the module.

How can I solve that?

(Sorry if it is difficult to understand. English isn't my native language...)

Thank you so much!
Justice
Reply With Quote