View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default get back data from userform

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 "".



Alex St-Pierre wrote:

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

--
Alex St-Pierre


--

Dave Peterson