Enable/Disable button

ekta

Registered User.
Local time
Today, 13:07
Joined
Sep 6, 2002
Messages
160
Hi:

I have a login form. Every user is assigned a userlevel. It is either 'admin' or 'user'. Once a user logs in successfully frmMain opens and user's userid and userlevel is stored in table, N_tblLocalUser, using append query. frmMain has Administrator button which, I want to be disabled if the userlevel is 'user' and enabled if user level is 'admin'.
This is the code that I have on the Open event of frmMain.

If DLookup("[USERLEVEL]", "N_tblLocalUser", "[USERLEVEL] <> 'admin'") = "user" Then
Me.btnUserMgmt.Enabled = False
Else
Me.btnUserMgmt.Enabled = True
End If

But it is not working. What else do I need to do to make it work?

Thanx
Ekta
 
Ekta,

I don't know where you stored their UserID when they
logged in, but something like this should do:

Code:
If Nz(DLookup("[USERLEVEL]", "N_tblLocalUser", "[USERID] = " & Me.UserID), "") <> "Admin" Then
  Me.btnUserMgmt.Enabled = False
Else
  Me.btnUserMgmt.Enabled = True
End If

Wayne
 
Thanx for replying Wayne:

This does not work. I am attaching the db. If you could please take a look at it.

Ekta
 

Attachments

ekta,

Your weren't using the DLookups properly.
You have code in that deletes all records from the user's table!
You lost all of your values when you closed your form.

I added global variables (see modules) for the user and level.
When the user enters password, I filled in the globals. The
next form uses the globals to enable/disable the button.

It's still a little rough, but with some work it'll be OK.

Wayne
 

Attachments

Hi Wayne:

It doesn't seem to be working. I see that you added 2 users in N_tblLocalUser. All my users are saved in N_tblPassword. Once they login in successfully their UserID and UserLevel are stored in N_tblLocalUser using append query. N_tblLocalUser is used to temporarily store the user logged in the db. I want to use this to enable/disable the button. When they logout of the database the user is deleted from N_tblLocalUser using delete query.

Ekta
 
ekta,

True, but I only had part of the database. Essentially I was
just trying to show you how the DLookups can be used.

Wayne
 
Thanx Wayne and Dave. I got it to work.
 

Users who are viewing this thread

Back
Top Bottom