Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activating userform and filling it with data form row where userform is activate Marthijn Beusekom via OfficeKB.com[_2_] Excel Programming 3 May 6th 05 05:44 PM
Writing data back via a userform Steph[_3_] Excel Programming 3 August 10th 04 04:39 PM
Change focus from Userform back to Sheet rocketslinger[_2_] Excel Programming 5 January 11th 04 02:31 PM
Focus back from modeless userform to sheet RB Smissaert Excel Programming 4 September 5th 03 04:21 PM
Must be a way to force focus back to sheet instead of UserForm - isn't there? Les[_4_] Excel Programming 2 July 29th 03 12:45 PM


All times are GMT +1. The time now is 11:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"