Results 1 to 4 of 4
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Richmond, VA

    Cannot create Global Variables

    I am creating these in a module, but they don't retain their value out side of it. Here's my code.

    Public Function Assign_Globals()
    On Error GoTo Err_Handler
        Dim gstrVendor_Name As String
        Dim gstrPath As String
        Dim gintAccounting_Period As Integer
        Dim gintFiscal_Year As Integer
        Dim gstrImport_File As String
        Dim gstrMacro_File As String
        Dim gstrStatement_Type As String
        Dim strCriteria As String
        strCriteria = "[Vendor_ID] = '" & Forms!frmUpdateCMX!cboVendor & "'"
        gstrVendor_Name = DLookup("[Vendor_Name]", "tblVendor", strCriteria)
        gstrPath = DLookup("[Path]", "tblVendor", strCriteria)
        gintAccounting_Period = Forms!frmUpdateCMX!cboAccountingPeriod
        gintFiscal_Year = Forms!frmUpdateCMX!txtFiscalYear
        gstrImport_File = DLookup("[Import_File]", "tblVendor", strCriteria)
        gstrMacro_File = DLookup("[Macro_File]", "tblVendor", strCriteria)
        gstrStatement_Type = DLookup("[Statement_Type]", "tblVendor", strCriteria)
        Exit Function
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_Function
        Resume Next
    End Function
    When I try to use Global or Public instead of Dim I get "Invalid attribute in Sub or Function."

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Global values must be OUTSIDE any function or sub. Usu. at the top of the module / form.
    I create a module called GLOBAL myself.

    label variables as:

    PUBLIC gstrVendor_Name as string

  3. #3
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Richmond, VA
    Ta Da!

    Thank you,


  4. #4
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    You might also look into TempVars, since you're basically using these to establish what appear to be static valuees that you wish to persist throughout the user's session.

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

Similar Threads

  1. Global Variables?
    By futurezach in forum Reports
    Replies: 4
    Last Post: 06-20-2013, 03:45 PM
  2. Replies: 2
    Last Post: 03-29-2013, 12:40 PM
  3. Replies: 2
    Last Post: 12-23-2011, 08:22 AM
  4. Setting global variables
    By Remster in forum Programming
    Replies: 1
    Last Post: 08-24-2011, 08:47 AM
  5. Create global function to calculate tax week
    By haylau in forum Programming
    Replies: 4
    Last Post: 03-15-2011, 10:31 AM

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