Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Global Variable syntax (ACCESS2003)

    Hi!
    I have global variables in Access Global Module.
    I need to add criteria to a query to search between Var1 and Var2.
    Somehow when I type in between Var1 and Var2 - Var1 and Var2 becomes "Var1" and "Var2"
    Is there a rule or syntax for search between 2 Global variables?
    and yes, both variablea are getting populated during run,

    Thanks

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Global Variable syntax (ACCESS2003)

    Hi,
    I'm afraid you can't use global variables like that. You could create a couple of simple functions that just return the variable values and use those as query criteria instead.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Global Variable syntax (ACCESS2003)

    Great! I think I did something like that at some point in my life...
    Here is my code, can you help me with the function?

    Option Compare Database
    Option Explicit

    Public AccStart As Integer
    Public AccEnd As Integer

    Global AccFrom As Integer
    Global AccTo As Integer


    Public Function Activate_Variables()

    AccStart = [Forms]![autoexec].[txt_From]
    AccEnd = [Forms]![autoexec].[txt_To]

    AccFrom = AccStart
    AccTo = AccEnd

    DoCmd.OpenQuery "GL DETAIL"

    End Function

    Thanks

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Global Variable syntax (ACCESS2003)

    If your autoexec form is open at the time, you can just refer to those two textboxes in the criteria of your query. If not, you need two functions like:
    <pre>Function GetStart() as Integer
    GetStart = AccFrom
    End Function
    </pre>

    and
    <pre>Function GetEnd() as Integer
    GetEnd = AccTo
    End Function
    </pre>

    and you can then use <code>=GetStart()</code> and <code>=GetEnd()</code> in your query criteria.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Global Variable syntax (ACCESS2003)

    Then I can go Between GetStart() and GetEnd() , correct?

    Thanks you so much and have a great day (it is morning here)LOL

Posting Permissions

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