On Sat, 25 Oct 2008 00:24:01 -0700, Denver
I can't guarantee that. However you're free to post back to the
newsgroup at any time.
I'm going to present a simple solution. Not the most secure or the
most features. Simple.
First thing we need is to find out who is using the app. Just ask
Windows who is logged in. See
http://www.mvps.org/access/api/api0008.htm for the code. Put this in a
standard module.
Next you need a table (say tblSecurity) with UserName (make this the
Primary key) and a bunch of Yes/No permission fields. If this were the
Northwind sample application I might have fields like IsAdministrator,
CanEnterOrders, CanViewOrders, etc.
Last is to write some one-liners in various places to check the
permissions. For example in the Orders form's Form_Open I would write:
if dlookup("CanViewOrders", "tblSecurity", "UserName='" &
fOSUserName() & "'") = False then Cancel = True
(note how the username is wrapped in single-quotes)
With this line I am checking if the CanViewOrders YesNo field in the
security table is set to False, and if it is, I set Cancel=True which
conveniently stops the opening of that form.
Why don't I write this code in the menu option or button click that
opens the form? Because there may be several ways to open the form and
I would have to be very careful not to forget any. The way I did it I
would have to write code only in one location.
To give someone readonly access I would set the form's AllowEdits
property to False:
(also in the Form_Open)
if dlookup("CanEditOrders", "tblSecurity", "UserName="" &
fOSUserName() & "'") = False then Me.AllowEdits=True
-Tom.