To get the user name of the currently logged in user add the following
module
to your database:
''''module starts''''
Option Compare Database
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal _
lpBuffer As String, nSize As Long) As Long
Public Function GetUser() As String
Dim strBuffer As String
Dim lngSize As Long, lngRetVal As Long
lngSize = 199
strBuffer = String$(200, 0)
lngRetVal = GetUserName(strBuffer, lngSize)
GetUser = Left$(strBuffer, lngSize - 1)
End Function
''''module ends''''
Add a table Users to your database with two text columns UserName and
GroupName. For each user add a row with their user name and 'group' name
e.g. Teachers or Admins. Strictly speaking you should add another table
Groups with column GroupName, with two rows with values Teachers and
Admins,
and relate the two tables, enforcing referential integrity. This prevents
a
group not in the Groups table being entered in Users (by a simple typo for
instance).
In the form's Open event procedure put:
Dim strUser As String, strCriteria As String
strUser = GetUser()
strCriteria = """" & strUser & """ IN (SELECT UserName " & _
"FROM Users WHERE GroupName = ""Sheridan"")"
Me.[cmdAddStudent].Enabled = Not IsNull(DLookup("UserName", "Users",
strCriteria))
where cmdAddStudent is the name of the button. By using a subquery within
the DLookup function's criteria this caters for a user possibly being in
both
the Teachers and Admins groups. It will work even if this isn't the case,
however.
From what you say it does sound like you are using a single .mdb file
installed in a shared folder on the server. This is not a good approach
in a
multi-user environment. What you should have is a front end on each local
machine, containing the forms, queries, reports etc and a back end file on
the server containing just the tables. You can change your database to
this
quite easily by using the built in database splitter wizard. This will
create a new back end and links to its tables in the front end file. You
should then move the back end file to a suitable folder on the server and
by
using the built in Linked table manager in the front end refresh the links
to
the back end in its new location. A separate copy of the front end should
then be installed on each local workstation along with Access itself. I
have
actually seen one of my applications installed like this but with Access
itself on the server. Although not normally recommended it did seem to
run
efficiently. Nevertheless it would be better to install Access on each
workstation.
The form of security you are using is very weak as far as the database is
concerned and could be easily subverted by a user. Access doe include its
own user and group security implementation, details of which you can find
at:
http://support.microsoft.com/default.aspx?scid=/support/access/content/secfaq.asp
Ken Sheridan
Stafford,
Mommio2 said:
Thanks, but I don't know HOW to do that. Here is how it is set up.
Database
is on the server. Each teacher computer on the network has a link to the
mdb file. We have the server permissions set up for teachers to have
read/execute and admins to have full control. How does Access know which
is
logging on so it can "fade out" the button if it is a teacher? Is this
the
correct way to set it up, or am I way off?