+ Reply to Thread
Results 1 to 3 of 3

Unable to pass variable between Userforms

  1. #1
    PGM
    Guest

    Unable to pass variable between Userforms

    I have thoroughly searched the group for an answer to this problem, but
    nothing seems to fit the bill.

    I have created a userform that allows the user to select a variety of
    options in order to process incoming data files. Since our group is
    currently in the middle of two different processing years, I need to
    have the user indicate the year in which they are working. This is
    done with an Application.Inputbox just before the userform is closed.

    I have declared the variable, MyYear, as Public in a general module,
    but it comes up defined as Empty when the next userform appears. I
    used the Application,Inputbox method so I could force the end-user to
    input a year, or exit the sub if they cancelled the operation, so I had
    to Dim MyYear as Variant.

    Is this why the variable won't be retained by the Public declaration?
    I have tried:

    Public MyYear As Variant

    but have no more luck than any other method.

    I have other variables in the general module that are coming through
    just fine, but none of them are created using an input box.

    Thanks in advance for any and all suggestions (including, "stop writing
    code."), and let me know if a snippet of my code would help.

    Paul


  2. #2
    Tom Ogilvy
    Guest

    RE: Unable to pass variable between Userforms

    Private Sub CommandButton1_Click()
    Dim dum As Variant
    dum = Application.InputBox("enter 4 digit year:", _
    Default:=Year(Date), Type:=1)
    If VarType(dum) = vbBoolean Then
    MsgBox "No year entered, quitting"
    Exit Sub
    End If
    MyYear = CLng(dum)
    Unload Me
    DoEvents
    'MsgBox MyYear

    End Sub

    In a general module:

    Public MyYear as Long



    worked for me.

    --
    Regards,
    Tom Ogilvy


    "PGM" wrote:

    > I have thoroughly searched the group for an answer to this problem, but
    > nothing seems to fit the bill.
    >
    > I have created a userform that allows the user to select a variety of
    > options in order to process incoming data files. Since our group is
    > currently in the middle of two different processing years, I need to
    > have the user indicate the year in which they are working. This is
    > done with an Application.Inputbox just before the userform is closed.
    >
    > I have declared the variable, MyYear, as Public in a general module,
    > but it comes up defined as Empty when the next userform appears. I
    > used the Application,Inputbox method so I could force the end-user to
    > input a year, or exit the sub if they cancelled the operation, so I had
    > to Dim MyYear as Variant.
    >
    > Is this why the variable won't be retained by the Public declaration?
    > I have tried:
    >
    > Public MyYear As Variant
    >
    > but have no more luck than any other method.
    >
    > I have other variables in the general module that are coming through
    > just fine, but none of them are created using an input box.
    >
    > Thanks in advance for any and all suggestions (including, "stop writing
    > code."), and let me know if a snippet of my code would help.
    >
    > Paul
    >
    >


  3. #3
    PGM
    Guest

    Re: Unable to pass variable between Userforms

    Thanks again, Tom!


+ 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