Help with control reference

chappy68

Registered User.
Local time
Yesterday, 21:27
Joined
Aug 15, 2011
Messages
76
I have a login form which remains open but not visible after successful login. On that form I have a hidden text box "txtSecLevel" which indicates the security level of the employee signing in.

I have a main menu form "frmMainMenu", with buttons to open the forms, which runs an IF statement to check security level before opening the requested form. I am having problems with the IF statement. It doesn't seem to be working since the current employee logged in on frmLogin has a security level of 1 and the form should not open but it does.

I am probably missing a small piece of info but can't seem to figure it out. I am using Access 2007 on Windows 7. The code behind the button on frmMainMenu is as follows:

Private Sub butPriTask_Click()
If Forms!frmLogin!txtSecLevel = 2 Or 3 Then
DoCmd.OpenForm "frmPrimaryTask", acNormal, "", "", , acNormal
Else
MsgBox "You are not authorized to access this form!", vbOKOnly

End If
End Sub

Thanks in advance for the assistance.
 
In Access VBA you cannot use syntax such as

Code:
[B]If Forms!frmLogin!txtSecLevel = 2 Or 3 [/B]
Correct syntax would be

Code:
[B]If Forms!frmLogin!txtSecLevel = 2 Or Forms!frmLogin!txtSecLevel = 3[/B]
Also, is the Field bound to txtSecLevel defined as a Number? If it's defined as Text you'd need Quotes around the 2 and 3.

Linq ;0)>
 
Missinglinq,

You have come to my assistance multiple times in the last couple weeks. I really appreciate it. Thanks again.
 
why not saving the security level as public variable, so you can close the login form ?
 
No problem, Chappy! That's why we're here!

Most experienced developers avoid using a global variable, smig, unless there is no other option available, because of the nasty habit Access has of dumping its value anytime an Error is generated.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom