• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1650
  • Last Modified:

Access 2007 tempvars losing its value

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?
0
LearningToProgram
Asked:
LearningToProgram
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.
0
 
Bill RossCommented:
Hi,

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...

Regards,

Bill
0
 
ramromconsultant Commented:
http://msdn.microsoft.com/en-us/library/office/bb257083%28v=office.12%29.aspx 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?
0
 
Armen Stein - Microsoft Access MVP since 2006PresidentCommented:
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,
Armen
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now