I have a macro that calls a user form. When the user clicks the "ok" button on the user form, a command-button-click macro runs, which sets a global variable ("formVal" to the value of one of the form fields. All that works well. My issue is when I then run a macro in a different module (but same workbook) the global variable is null.
Here is the code in the user form. "msgboxtest" works when placed on the userform code page, but when I move it to a module it shows that the variable is null. (I also have "Option Explicit Public formVal as String on the module code page)
Here is the code in the user form. "msgboxtest" works when placed on the userform code page, but when I move it to a module it shows that the variable is null. (I also have "Option Explicit Public formVal as String on the module code page)
Code:
Option Explicit
Public formVal As String
Private Sub CommandButton1_Click()
formVal = ComboBox1.Text
SGF.Hide '(SGF is the name of the user form)
Call msgboxtest
End Sub
Sub msgboxtest()
'This works fine when I have it one the same page as the user form code, but when I move it to a module it says the variable is null
MsgBox formVal
End Sub