Results 1 to 8 of 8
  1. #1
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67

    Public variable is not being retained for the duration of the project


    I set 2 Public variables at the top of the standard module. When the function is called from within the form class object, the 2 variables get valued which I verify using the watch window. As soon as that function is returned from the standard module, back to the form class object, the 2 variables loose there value. What am I over looking?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Try Global instead of Public.
    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.

  3. #3
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67
    Thanks June7. I should have mentioned that I already tried that as well, but got the same results; Nothing!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Global and Public both work for me.

    Post your code or provide db.
    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.

  5. #5
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67
    I want to have this public variable shared between forms?

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Check out Tempvars. I successfully use them frequently as global variables.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Yes, I use Global or Public variable to share value between forms.

    I know about TempVars but never used.
    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.

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Check all your form and function code to ensure that you have not re-declared those global variables in a Dim statement. A variable declared in a function/sub will take precedence over the global one with the same name.

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

Similar Threads

  1. Displaying a Public Variable on a form
    By swenger in forum Programming
    Replies: 1
    Last Post: 06-23-2016, 01:56 PM
  2. Replies: 5
    Last Post: 04-27-2015, 02:40 PM
  3. Replies: 1
    Last Post: 08-03-2014, 07:48 PM
  4. Project Duration
    By Ian Frost in forum Queries
    Replies: 2
    Last Post: 05-23-2014, 06:48 AM
  5. How to use global/public variable
    By mrbabji in forum Programming
    Replies: 7
    Last Post: 05-18-2013, 10:08 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