CurrentUser Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I make this code have multiple users in it? Right now I have "Admin"
as the user but I want to be able to have specific multiple users. I tried
using "Or" but I was getting error messages when I did this. Can anyone help?

If CurrentUser() = "Admin" Then
Me!CEODate.Enabled = True
Me!CEODate.Locked = False
Else
Me!CEODate.Enabled = False
Me!CEODate.Locked = True
End If
 
First of all you need to implement user level security in Access. You
haven't done that yet. Download and study the security FAQ
http://support.microsoft.com/?id=207793 and the Security Whitepaper
http://support.microsoft.com/?id=148555

I've also outlined the detailed steps at
www.jmwild.com/AccessSecurity.htm

When you implement security, I wouldn't assign permissions to individual
users. Instead create groups (like Sales, Quality Control, Management,
etc). and assign permissions to the groups. Then it is just a matter of
adding/removing users to the appropriate group. As for locking the controls
on your form, just determine if the current user is a member of a certain
group (there's code in the FAQ for this), and if they are unlock the
controls, else lock them.

--
Joan Wild
Microsoft Access MVP

Secret said:
Hi Joan,
What I'm trying to do is make it easier to enable/lock fields in one
of my forms depending on what user is logged on. If you take a look
at my db on the 2005 Form you can see under the open event what I'm
talking about. I would have to create a rather large code for all my
users for each field on that form. There are over 50 fields on that
form so I wanted to be able to do this via a table so I can change
permissions instead of going into the form to change the code.
Certain users will only have access to certain fields on a form.

Joan Wild said:
I would, instead, assign permissions to groups rather than users.
You can use the function in the security FAQ to determine if a user
is a member of a group.
http://support.microsoft.com/?id=207793

--
Joan Wild
Microsoft Access MVP

Secret said:
Well actually each field is specific to certain users so I would
need to be able to set permissions for specific fields. Can this be
done with this table?

:

It's depend how often you are going to use this table, to how many
forms you want to set permissions.

The most simple permission table, will contain two fields
1. Form name , so you can use this table for several forms
2. User name , enter the name of the users you want them to have
permission, such as Admin

The sample code I gave you, will look for a record of the user name
+ form name, if it find a match, it will set the permission to
true. else to false

If Dcount("[User_Name]","[Table Name]","[User Name] = '" &
CurrentUser() & "' And [Form Name] = 'Form1'") > 0 Then
Me!CEODate.Enabled = True
Me!CEODate.Locked = False
Else
Me!CEODate.Enabled = False
Me!CEODate.Locked = True
End If

--
The next line is only relevant to Microsoft''s web-based interface
users. If I answered your question, please mark it as an answer.
It''s useful to know that my answer was helpful
HTH, good luck


:

How exactly would this table look? I'm a little unclear how to set
up a table that defines permissions. I like your idea though I
wouldn't know where to being with this table.

:

I would create a table that holds the users names that has a
permission, and then use a dcount to check if the user been
defined in this table, that way it make it easier adding users or
removing users permission

If Dcount("[User_Name]","[Table Name]","[User Name] = '" &
CurrentUser() & "'") > 0 Then
Me!CEODate.Enabled = True
Me!CEODate.Locked = False
Else
Me!CEODate.Enabled = False
Me!CEODate.Locked = True
End If
===============================
To use few selections as you tried, try this
If CurrentUser() = "Admin" Or CurrentUser() = "User2" Or
CurrentUser() = "User3" Then
Me!CEODate.Enabled = True
Me!CEODate.Locked = False
Else
Me!CEODate.Enabled = False
Me!CEODate.Locked = True
End If

--
The next line is only relevant to Microsoft''s web-based
interface users.
If I answered your question, please mark it as an answer. It''s
useful to know that my answer was helpful
HTH, good luck


:

How do I make this code have multiple users in it? Right now I
have "Admin" as the user but I want to be able to have specific
multiple users. I tried using "Or" but I was getting error
messages when I did this. Can anyone help?

If CurrentUser() = "Admin" Then
Me!CEODate.Enabled = True
Me!CEODate.Locked = False
Else
Me!CEODate.Enabled = False
Me!CEODate.Locked = True
End If
 
Back
Top