Results 1 to 2 of 2
  1. #1
    jeffatwork is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    3

    Global Variable for Query Name

    Newbie here, so be easy on me ...

    How to I create a global variable (a query name) name within my reports. I have numerous reports that reference a specific query. Within those reports, I have numerous aggregate functions that reference a specific query. I'd like to create a global variable so that I can easily reference different queries just by changing a single variable.

    Example:


    DAvg("term","qryLease","term")
    DMin("term","qryLease","term")
    DMax("term","qryLease","term")

    I'd like to be able to change the "qryLease" to variable.

    Where do I create the variable and how do I reference that variable?


    Thanks in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Declare global variable as a String type in a general module. Set its value in some procedure then use it in VBA:

    x = DAvg("somefield", varName, "anotherfield=somecriteria")

    Global variables can only be referenced in VBA.

    TempVars can be referenced in queries and ControlSource property.

    Can also populate a control on form and reference that.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Global Variable
    By gtg430i in forum Programming
    Replies: 11
    Last Post: 03-10-2014, 05:00 PM
  2. Can't See Global Variable
    By CementCarver in forum Programming
    Replies: 12
    Last Post: 09-19-2013, 12:28 PM
  3. Global variable
    By ramdandi in forum Queries
    Replies: 3
    Last Post: 12-18-2011, 01:01 AM
  4. Replies: 4
    Last Post: 07-14-2011, 12:55 PM
  5. Dlookup in query using Global variable
    By newwales in forum Access
    Replies: 1
    Last Post: 06-03-2011, 03:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums