get back data from userform

A

Alex St-Pierre

Hi,
I have a button in my userform which allow me to select a file.
After selecting the file, I unload the userform by the data in the form are
not saved...

ex:
Sub macro()
Dim strPath as string
UserForm1.Show
'then treatment of the data
Msgbox(i) gives nothing... I expected to have number 4.
End Sub

If I click on Button #3, then
Private Sub CommandButton3_Click()
ChDrive "V:\ACE"
ChDir "V:\ACE"
strPath = Application.GetOpenFilename()
If strPath = False Then End
strPath = CurDir
file = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
i = 4
UserForm1.Hide
End Sub
 
D

Dave Peterson

If you make i (and strPath) a public variable in a General module, I bet it
would work:

Public i as long
dim strPath as string

Sub macro()
Dim strPath as string
UserForm1.Show
'then treatment of the data
Msgbox(i) gives nothing... I expected to have number 4.
End Sub

But the way your code is written, i and strPath are local to that one
procedure. When that procedure ends, then i and strPath fail to exist.

And since i and strpath are both unitialized variants, they'll return "".
 

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