+ Reply to Thread
Results 1 to 2 of 2

Questions on passng data between UserForm, Module

  1. #1
    Dennis Benjamin
    Guest

    Questions on passng data between UserForm, Module

    Hey All

    I'm new to VBA and just getting the hang of it. Would appreciate any help on
    the following, where I'm a bit confused about namespaces.

    I've written a bunch of code and now need to use a Userform to get input,
    specifically values for two variables nAliquots and vAliquots. I'm using a
    TextBox, and the only way I could pass the values back to my module (stored
    in thisWorkBook) is like so:

    Private Sub OK_Click()
    ThisWorkbook.GetAliquotValues
    Unload Me
    End Sub

    Where the GetAliquotValues routine pulls the values stored in the TextBox.
    It seems kludgy to me to have to call a function back in the WorkBook - I'd
    like to be able to do something like

    Private Sub OK_Click()
    nAliquots = me.TextBox1.Value
    vAliquots = me.TextBox2.Value
    Unload Me
    End Sub

    And have the variables in the Workbook loaded w/ the users data. I declared
    nAliquots and vAliquots as Public but it didn't work.


    So.... is there a straightforward way to share variables between UserForms
    and Modules? Or am I thinking about this incorrectly?

    Thanks!



  2. #2
    Mike Fogleman
    Guest

    Re: Questions on passng data between UserForm, Module

    Where exactly are they declared? I declare my Public variables at the very
    top of a general module (or right under Option Explicit) outside of, and
    before any subs, functions, or procedures.

    Mike F
    "Dennis Benjamin" <dbenjamin@seagen.com> wrote in message
    news:%23Y0vlIj9FHA.1188@TK2MSFTNGP12.phx.gbl...
    > Hey All
    >
    > I'm new to VBA and just getting the hang of it. Would appreciate any help
    > on the following, where I'm a bit confused about namespaces.
    >
    > I've written a bunch of code and now need to use a Userform to get input,
    > specifically values for two variables nAliquots and vAliquots. I'm using a
    > TextBox, and the only way I could pass the values back to my module
    > (stored in thisWorkBook) is like so:
    >
    > Private Sub OK_Click()
    > ThisWorkbook.GetAliquotValues
    > Unload Me
    > End Sub
    >
    > Where the GetAliquotValues routine pulls the values stored in the TextBox.
    > It seems kludgy to me to have to call a function back in the WorkBook -
    > I'd like to be able to do something like
    >
    > Private Sub OK_Click()
    > nAliquots = me.TextBox1.Value
    > vAliquots = me.TextBox2.Value
    > Unload Me
    > End Sub
    >
    > And have the variables in the Workbook loaded w/ the users data. I
    > declared nAliquots and vAliquots as Public but it didn't work.
    >
    >
    > So.... is there a straightforward way to share variables between UserForms
    > and Modules? Or am I thinking about this incorrectly?
    >
    > Thanks!
    >




+ 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