PDA

View Full Version : Solved: Syntax for Using TempVar Global Variables



SimonB
10-01-2008, 01:22 PM
I am trying for the first time to use the new VBA global variable feature in Access 2007, the TempVars collection. I have a form for the user to log into the DB, using a Username and Password. I have limited the allowed number of login attempts, and need to increment a counter for each attempt. Here's what I am doing:
I declare three TempVars on the Form_Open module this way:
TempVars("CurrentUserName").Value = "Username" ' Spaceholder name until set by user.
TempVars("LoginAttemptCounter").Value = Val("0") ' Initial value, to be incremented with attempt.
TempVars("MaxAllowedLoginAttempts").Value = Val("3")
The login screen has an OK button. The module associated with that button's OnClick event loops through a process of validating the entered login credentials, and it has an incremented counter for each time the button is clicked. It has this check in it:
If [TempVar]![LoginAttemptCounter] < [TempVar]![MaxAllowedLoginAttempts] Then...
The compiler doesn'y like this statement. I get the error message, "Microsoft Access can't find the field '|'referred to in your expression. My syntax is bad, somehow. Does anyone see the problem, and know how to fix it?
Thanks in advance, SimonB

CreganTur
10-01-2008, 01:48 PM
Well... if you're using "If [TempVar]![LoginAttemptCounter] < [TempVar]![MaxAllowedLoginAttempts] Then" in VBA, then the issue is that you're trying to use SQL syntax in VBA... which doesn't work.

If you're wanting to check this in VBA then you need to use something like:
If TempVars("LoginAttemptCounter").Value < TempVars("MaxAllowedLoginAttempts").Value Then...

I can't test this out... don't have 2007 here at work. But it's the right direction for you.

SimonB
10-01-2008, 06:19 PM
That did the trick. You nailed it! Thank you, Randy.

czach
10-09-2010, 09:08 PM
hello guys.. how do you place values from TempVars to labels in form?..

i tried this but an error appears saying "Object doesnt support this property or method"

Me.lblDate = TempVars("passDate").Value

hansup
10-10-2010, 09:36 AM
Assign the value to the label's Caption property.Me.lblDate.Caption = TempVars("passDate").Value