Access 2007 tempvars losing its value

Posted on 2012-09-08
Last Modified: 2012-09-14
I've got an Access application that sets the current user when they log in to tempvars!currentuserid.
I've used the exact same form in other applications with no problem.
With this application, the value for tempvars!currentuserid goes null at some point after the user has successfully logged in. In other words, the value is set correctly for some period of time, and then it later (at some seemingly arbitrary point) loses it's value.
I've checked for the obvious things such as tempvars.remove, tempvars.removeall, and setting the value to something else but none of that is in the code. After it is set, there is no use of  tempvars!currentuserid except to get its value.
Can anyone think of what could cause this to happen?
Question by:LearningToProgram
    LVL 84

    Accepted Solution

    I would assume something is overwriting it, but then TempVars is a relatively new addition to Access and could be experiencing growing pains.

    To me, the simplest way to store session-level variables is to use the hidden form technique:

    Build a form that is started as Hidden when the application starts, and add Textboxes as needed to store those items. For example, you might have a textbox named txUser, so when you log in you can store the current user in that:

    Forms("YourformName").txUser = TheCurrentUser

    If you need to get that value:

    Msgbox "The current user is " & forms("YourFormName').txNuser

    Outside of that, the only suggestion I could make would be to (a) more thoroughly examine your code to insure you're not overwriting the value somewhere, (b) try to track down a reproducible version of the event and (c) make sure that the machine's Office and Windows installation are fully up to date. Oddities like this can sometimes be caused by invalid/corrupt installations of either Office or Windows.
    LVL 14

    Expert Comment

    by:Bill Ross

    I suspect you have unhandled errors somewhere in your code.  When the code fails you get a debug and break and that will reset your tempvars.

    Make sure all your procedures/functions have correct error trapping...


    LVL 17

    Expert Comment

    by:ramrom says
    " If you do not remove a TempVar object, it will remain in memory until you close the database. "
    debug-break should not remove it.

    "growing pains" nice euphemism for MS screws up again?
    LVL 9

    Expert Comment

    by:Armen Stein - Microsoft Access MVP since 2006
    BillDenver, the behavior you describe is true for global variables, but does not apply to TempVars.  TempVars values are retained after an unhandled error, debugging activity, and code being stopped.

    I haven't seen TempVars values get cleared spontaneously during a session, so I'm with LSMConsulting that some code, somewhere, is clearing it.

    To help narrow down when the value is getting cleared, try setting a Watch on the expression tempvars!currentuserid.

    Hope this helps,

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now