Results 1 to 8 of 8
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need to use public value across standard modules (97)

    Need to use public value across standard modules
    I declared a public variable in a standard code module & need to reference this value in another standard module, how can I do that? Possible?

  2. #2
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need to use public value across standard modules (97)

    I use this method several places in my code. If you declare the variable in "Modules" as public, they will be available for the entire program to see as long as the program is running. If you declare the variable inside a form's code, for instance, it will only be available for that part of the code. Also, anytime a run time error is created, the variable will be dropped and need to be re-set.

    Thanks,
    Mark Santos

  3. #3
    4 Star Lounger
    Join Date
    Jun 2001
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need to use public value across standard modules (97)

    I get a

  4. #4
    4 Star Lounger
    Join Date
    Jun 2001
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need to use public value across standard modules (97)

    oh I get it, I didn

  5. #5
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need to use public value across standard modules (97)

    Well you can leave the option explicit statement, but the public declaration needs to be in the "Modules" section and not attached to something like form code. For instance you can have a form with code attached. If this is where the public variable is being declared you will only see that variable while that form is open. A variable declared as public in the "Modules" section lives the entire time the app is running.

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

    Re: Need to use public value across standard modules (97)

    Actually, it's the section of the module where you dim public and module level variables is called the declarations section.
    Charlotte

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

    Re: Need to use public value across standard modules (97)

    Don't comment out Option Explicit. It keeps you honest and helps you find spelling errors that will otherwise cause strange problems that will be very difficult to debug because you don't know what's wrong.

    You can declare variables in two different places, within a code routine or at the top of the module ahead of any Subs and Functions. Anything you declare Public has to be declared there because you can't create a public variable from within a code routine. All variables declared within a routine are limited to local scope.
    Charlotte

  8. #8
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need to use public value across standard modules (97)

    That's what I meant but your words are better then mine!

Posting Permissions

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