Restricting display of information

garywood84

Registered User.
Local time
Today, 23:35
Joined
Apr 12, 2006
Messages
168
I have built a database to be used by several users. One of the tables contains some fields which I don't want some of the users to be able to see.

All users log in to the database with their own username and password.

How can I hide the fields to everyone except a specific group of users?

Thanks,

Gary
 
In your userlog (assuming you're capturing userIDs), you have a lookup table for each user that can see specific fields. In that table, just put in the UserIDs that you want to see certain fields. If the logged in user is not in that lookup table, then that field is not visible. It'd look something like this:

Sub MakeFieldsVisible(UserID As String)

Code:
If Not(IsNull(DLookup("[Your_UserID_Field_Name]","Name_Of_UserID_Lookup_Table","[Your_UserID_Field_Name]='" & UserID & "'"))) Then
.
.
<make fields visible>
.
.
End If

End Sub

The above assumes you have the controls not visible by default.
 
In general, what you are trying to do is a complex function. Rather than make the form super smart in deciding to display or not to display a given field, I would take a totally different approach.

1. Build a switchboard form. Your users will do everything from the switchboard and NOTHING from the DB windows. (Except give yourself or your developers an "out" that lets them close the switchboard.)

2. Devise TWO forms with similar but not identical names. One is for your limited users. The other is for your less-limited users.

3. Have the button on the switchboard look at the user to decide which of the two forms to bring up. Since the users won't SEE the true "forms" window, they would never know the difference.

I understand your display is probably not set up for this, but it is far less work to do it this way than to do it in a wide-open environment.
 
I absolutly agree with this solution. I made this code so the admin can login and the users have no acces to things they should not have acces to.

Code:
Private Sub Loginbutton_Click()
        
    If (Me.Txtfieldinform1 = "Username") And (Me.Txtfieldinform2 = "Password") Then
    DoCmd.Close
    DoCmd.OpenForm "name of form for admin"
        

      Else

    Me!Label.Caption = "(Invalid username or password)"
    Me.Txtfieldinform1 = Null
    Me.Txtfieldinform2 = Null
    End If
End Sub

when opening the database you open a form whitch gives you the choose enter or admin login. Ad admin login you make a small login form apear. on this form you schould make 2 txt field independet a button ( loginbutton) and a Label.This is what my login looks like.

login.JPG
 
Last edited:
Thanks for the replies. I'm sorry for the delayed reply - I've been distracted from my database development by other things over the last week.

Reading what's been posted above, I think I need to have two forms, one which shows the confidential information and once which doesn't. I then need to check the username of the current user, see if that username features in the username field of a table containing one record for each user who is allowed access and then, if it is, show the form with the confidential information, and if it isn't show the copy without.

So, my next question is this: once I've got the username as a string (strUsername), what code can I use to check if strUsername is in tblUserAccess in field Username?

I think, once I know this, I can do the rest because an If statement should suffice.

Thanks in advance,

Gary
 
DCount("*", "tblUserAccess", "Username = '" & strUsername & "'") > 0
 
lagbolt,

I've just been working on my database using this code, and realised that I forgot to thank you for it. I'm sorry I didn't post back, earlier, but the code has worked perfectly and does exactly what I needed.

Many thanks,

Gary
 
Gary:
That's very kind. I'm glad I could offer something you could use.
Cheers,
Mark
 

Users who are viewing this thread

Back
Top Bottom