+ Reply to Thread
Results 1 to 3 of 3

get back data from userform

  1. #1
    Alex St-Pierre
    Guest

    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. #2
    Dave Peterson
    Guest

    Re: 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. #3
    Dave Peterson
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1