| the Manx Man's MS Access Pages to subscribe - click here Using Groups in Access Security (035) NOTE:This article has been converted to our new web site. See it here. This article assumes that you are familiar with setting up Access
security. My favourite tip in this regard is - ALWAYS CREATE A CUSTOM SECURITY FILE (or
MDW). If you have not recently read a good article on Access security, here is one. I
recommend it. Read it NOW. One of the tips in that article is, never use a user's username to determine some security related permission. Always use groups, as they are easier to maintain. Then assign your user to the appropriate group(s). The user will have the highest level of security available from all and any groups that they belong to. Let's look at a simple example. (all my examples assume that you have DAO set as the default data manipulation tool. If you are not sure what this means, and you are using Access 2000 or higher, click here. ) Let's say that you want all your manager level people to see an additional command button on a form. Or, perhaps the opposite is true. You do not want them to see it!!!
Determining What Groups a User is in
In Form's Open Event
How Does it Work? The GroupScore function sets up a reference to the current user's user properties and loops through all the groups that that user belongs to. By using powers of 2 to assign a "score" we can come up with a number that allows us to determine at any time whether they belong to a specific group. This works because of the binary pattern of powers of 2 and the functioning of the "and" operator. For example, if the user belongs to both the Supervisor group and the Manager group, their group score would be 12. Next, we compare their group score of 12 to a Manager's pure group score of 8, (12 and 8). If the result of that "and" operation equals 8 (which it does) then we know they are a manager. Alternatively, (12 and 4) equals 4 so they are also a supervisor. Further Suggestions Assign the GroupScore to a global variable so the computer wastes less time each time it needs to check a user's groups within the same session. Next Issue What's next? Several more articles about creating a table completely from VBA code, and using an Excel file to define the fields in the table. See the first 2 parts of that series at tip021 and tip022.
|
tip # 035 || previous tip || next tip