Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Location
    Grand Junction, Colorado
    Posts
    12

    Unanswered: Global Variables

    Trying to set a global variable to use later in forms for default inputs.

    Table is tblDefaultUser with three columns

    UserDefaultID (PK)
    UserID
    DivisionID

    query is qryDefaultUser with three columns

    UserDefaultID (where = 1)
    UserID
    DivisionID

    In my modules is this...
    Code:
    Option Compare Database
    Option Explicit
    
    Global varDfltUser As String
    
    varDfltUser = DoCmd.GoToRecord(acDataQuery, qryDefaultUser.UserID, acFirst)
    I get 'compile error: Invalid outside procedure'

    Thanks,
    John

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    A global variable must be declared in an independent module, not in a class module (the module of a form is a class module). If the variable will only be used inside the form, you can declare it as Private. Otherwise you need to declare it in a new or existing standard module (i.e. a module you can see in the database window of your application). In such case, it's recommended to declare it as Public instead of Global.
    Have a nice day!

Posting Permissions

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