I am a new to VBA and have a simple but aggravating to me question.
I am trying to set a variable in a user form when OK is clicked and then have the variable available to the calling sub procedure for use. But the variable always gets dropped. I would prefer to not make it PUBLIC since it shouldn't have to be. My latest code was an attempt at using STATIC but it still gets dropped. What am I missing ?
Here is an example of what I am doing in a simpler block of code:
VBA code
Sub Get_Variable()
form_System.Show
MsgBox " Within VBA the variable is " & Save_VARIABLE
End Sub
**********************************************
User Form form_SYSTEM code
Sub button_OK_Click()
Static save_VARIABLE As String
If ob_01 = True Then
save_VARIABLE = "One"
ElseIf ob_02 = True Then
save_VARIABLE = "Two"
ElseIf ob_03 = True Then
save_VARIABLE = "Three"
Else
MsgBox " You failed to make a choice!!"
Exit Sub
End Ifthe Form the variable is " & save_VARIABLE
Unload form_System
End Sub
The first message box, initiated by the FORM code, gives the variable, the second message box, initiated by VBA procedure, does not.
The manuals are very weak on explaining this.
Thanks for any help. -LJS
I am trying to set a variable in a user form when OK is clicked and then have the variable available to the calling sub procedure for use. But the variable always gets dropped. I would prefer to not make it PUBLIC since it shouldn't have to be. My latest code was an attempt at using STATIC but it still gets dropped. What am I missing ?
Here is an example of what I am doing in a simpler block of code:
VBA code
Sub Get_Variable()
form_System.Show
MsgBox " Within VBA the variable is " & Save_VARIABLE
End Sub
**********************************************
User Form form_SYSTEM code
Sub button_OK_Click()
Static save_VARIABLE As String
If ob_01 = True Then
save_VARIABLE = "One"
ElseIf ob_02 = True Then
save_VARIABLE = "Two"
ElseIf ob_03 = True Then
save_VARIABLE = "Three"
Else
MsgBox " You failed to make a choice!!"
Exit Sub
End Ifthe Form the variable is " & save_VARIABLE
Unload form_System
End Sub
The first message box, initiated by the FORM code, gives the variable, the second message box, initiated by VBA procedure, does not.
The manuals are very weak on explaining this.
Thanks for any help. -LJS