That's because ComplaintForm doesn't know anything about variables defined
by the Logon form, even through you've declared them as Public. Not only
that, but you've closed the Logon form, so that variable doesn't even exist
anymore!
Try passing the value of userPermission to the ComplaintForm as the OpenArgs
parameter:
DoCmd.OpenForm "ComplaintForm", acNormal, OpenArgs:=userPermission
(There's really no need for the other parameters you had in your OpenForm
method, as they were all the defaults)
Then, in ComplaintForm, try:
Me.button1.Enabled = (Nz(Me.OpenArgs, 0) = 1)
Incidentally, if the Logon form was still open, so that the userPermission
variable still existed, you could refer to it as
Form_Logon.UserPermission
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
DeanT said:
That prevents the error message, however when I add the following to the
OPen
event of the Complaintform:
Me.button1.Enabled = (userPermission=1)
It always disables the button no matter what value is in the permission
table.?????
Douglas J. Steele said:
See whether it makes a difference putting the DoCmd.Close after you open
the
other form.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
What am I doing wrong?
Here is my coding below and when I execute the Logon procedure I get an
error msg #2467 "The expression you entered refers to an object that
is
closed or doesn't exist" and the debugger highlights the
'UserPermission =
DLookup..... line.
Hereis my module coding;
Option Compare Database
Public UserPermission As Integer
Private Sub Command4_Click()
strUser = Me.UserName & ""
If StrComp(Me.Password, Nz(DLookup("Password", "UserTable", "UserName="
&
"""" & strUser & """"), ""), 0) = 0 Then
DoCmd.Close acForm, "Logon"
UserPermission = DLookup("[Permission]", "[UserTable]", "[UserName]
=
'"
& Me![UserName] & "'")
DoCmd.OpenForm "ComplaintForm", acNormal, "", "", , acNormal
Else
MsgBox "Invalid Username or Password"
End If
End Sub
:
Where do you declare strUser? I would expect the permission
value to be in the same place. But if you never did declare
those variables, they won't be around later when you need
them.
Assuming you are doing what John suggested about declaring
them Public in a standard module, then assign the permission
DLookup to the variable right after you verify the password
(or any later time when you need to check it).
As an aside, you need to be aware that any enterprising
person can print out a copy of your user table to get a list
of all the passwords.
--
Marsh
MVP [MS Access]
DeanT wrote:
I am having trouble putting this all together:
My UserTable has following fields:
UserName Text
Password Text
Permissions Number
When I click the Logon command button on the Logon form the following
procedure executes:
Option Compare Database
Private Sub Command4_Click()
strUser = Me.UserName & ""
If StrComp(Me.Password, Nz(DLookup("Password", "UserTable",
"UserName="
&
"""" & strUser & """"), ""), 0) = 0 Then
DoCmd.Close acForm, "Logon"
DoCmd.OpenForm "ComplaintForm", acNormal, "", "", , acNormal
Else
MsgBox "Invalid Username or Password"
End If
End Sub
Where do I insert the DLookup function you suggested and where do I
insert
the Global Permission as Integer code?
:
We need to know what the logon form is doing, how you are
deriving the user permission level and where you are putting
it. It might be as simple as what Dean suggested, or ???
My use of a global variable was just so I could demonstrate
how to enable/disable controls. I did not mean to imply
that it was a good way to do it. A (hidden?) text box on an
always open form would be better. You might already have
that or you might be doing someting else with the value.
DeanT wrote:
How do I get the PermissionLevel value from the logon table to a
Global
Variable named UserPermission ?
:
DeanT wrote:
I have a database with a logon table which contains UserID,
password,
PermissionLevel
When user logs in with proper password, the main menu form is
opened. On the
main menu form are several command buttons which open other
forms.
I want
these command buttons to be enabled/disabled depending on the
user's
permission level. Level 1 enables, level 0 disables.
How do I code to do this and where do I enter code.?
Put the code ib the main menu form's Open (or Load) event
procedure. Since you didn't say where/how the permission
level value gets from the logon form to the main menu form,
I will assume it's in a global variable named
UserPermission:
Me.button1.Enabled = (UserPermission=1)
Me.button2.Enabled = (UserPermission=1)
. . .