Results 1 to 2 of 2

Thread: Scope of Variables

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Posts
    78

    Post

    Prior to saying rtfm, here's the stuff I'm encountering:

    I have a module that is loaded first thing when a database opens; inside of it is a variable I declare.

    I've tried declaring it in the following two ways:

    Dim strVar as string
    Public strVar as string

    that's neither here nor there; what happens after that is that I wish to call it in a different module (one attached to a form) but it won't compile. Tells me undefined variable!

    I don't understand; I've set it up as a public variable in the first module that should be loaded into memory.

    Any ideas?

    Another quirky thing I've been wondering about it this:
    I have a form based on a query. The query relies on a function.
    I call the function in the form's Open event, but the form still comes up blank, unless I close it and reopen it.

    I worked around it by creating a splash form that calls the data, opens the main form, then closes itself, but I feel like this is a sloppy way to work it.

    Any ideas?

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    When you say "Module" I assume you mean "Sub", "Function" or "Procedure" although using "Module" that way is not the normal usage of the word. But enough about that. To solve your problem, add a real code module (Project>Add Module) to your project and move your Public strVar as string statement to it. strVar will then have global scope and will be available anywhere in the app.

    ------------------
    Marty
    Can you buy an entire chess set in a pawn shop?

Posting Permissions

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



Click Here to Expand Forum to Full Width