Passing Form Values

D

David

I've a form that allows the user to enter a filename.

I want the filename entered to be used in another function, the
function that calls the form in the first place, but the variable
appears to be volatile, ie it's not being passed back to the calling
function.

How do I get the variable passed back? I could do it by writing it
onto the worksheet but is there a way of doing it just with variables?

Let me know if you want to see the code.

Thanks!
 
B

Bob Phillips

One way is to have a public property in the form and test that afterwards

Dim myForm As UserForm1

If myForm Is Nothing Then Set myForm = New UserForm1
myForm.Show
MsgBox myForm.myProp
Set myForm = Nothing

In the form have a public variable

Public myProp as Boolean

and set it in the form code. Ensure that in the form you hide when exiting,
not unload.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

Dave Peterson

Another way is to use a Public variable in a General module (not in the userform
code module).

Public MyFileName as String 'or whatever you want.

Then this variable will be able to be seen by any procedure.
 
B

Bob Phillips

A form property can be seen by any procedure as well.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

Dave Peterson

But I don't have to worry about hiding or unloading (after I change the
variable).
 
B

Bob Phillips

Dave, you don't have to worry anyway. It's only Excel.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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

Top