Passing variable values from userforms

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Is it possible to pass a value from a variable that is in
a userform? I have a date that a user inputs in a
textbox. This date is stored in a variable. Then when
the user clicks the OK button on the userform, a module is
called. I need that variable fromt he userform to be
accessable from the module. I know its possible to pass
variable values between code modules by using the public
statement, but for some reason I cant get it to work from
a userform to code module. Is this possible?


Thanks
Todd Huttenstine
 
In the userform code module:

Public MyVar


Private Sub CommandButton1_Click()
MyVar = Rnd()
MyMacro
End Sub

' note that the Userform is not unloaded or the value in MyVar will be lost.

in a general module:

Sub MyMacro()
MsgBox UserForm1.MyVar
End Sub

But you could also just use

msgbox Userform1.Textbox1.Value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top