Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Nov 2001
    Location
    Newark, New Jersey, USA
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Declaring a public variable (Access 2002)

    What's the best method using vba in Access to transfer a variable from one form to another?

    I need to be able to set the value of a field on form "A" as a variable, and be able to grab that variable and insert it on form "B." Any thoughts would be appreciated.

    Thanks,
    Rich

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Declaring a public variable (Access 2002)

    If both forms will be open simultaneously (even for an instant), you can simply use (in VBA code):

    Form_FormB.txtMyControl = Form_FormA.txtMyControl

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Declaring a public variable (Access 2002)

    You could create a global var class module to contain any and all variables used globally.
    The class functions the same as any old public var, but organizes the variables in the class.

    If the forms are both loaded (but not necessarily visible) you can create form properties
    to hold the values -- but that seems a bit stuffy if you are only propagating a field value
    from form A to a field on form B. Mark's solution is just fine for that.

    And, of course, you can just use a global variable -- there, I said it.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Declaring a public variable (Access 2002)

    You asked the same question in this thread and got answers there as well. Please don't post the same question to several boards. It is a violation of <!rule=14>Rule 14<!/rule> on cross-posting. Since this is an Access question, I'm going to lock this thread and ask that any other replies be posted to the Access thread.
    Charlotte

Posting Permissions

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