![]() |
get back data from userform
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 |
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 |
get back data from userform
Oopsie!
dim strPath as string should be Public strPath as string Dave Peterson wrote: 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 -- Dave Peterson |
All times are GMT +1. The time now is 09:36 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com