kibokoyao:
My apologies for the delay, I've a major project in the lab and visitors from other locations; thus, a lot of "fires" to handle. - I call it "job security!"
As we work thru this, please keep in mind that Bytes is not a code writing service. Instead we try to help each other thru a rough spot or to get back on the right path. :)
For this basic example:
1) For a simple set of groups, say "admin," "Spvsr," "Lead," and "User"
2) Form named "zfrmAlpha"
3) control on form, text box, named "zctrltxtAllowSome" that well let most people use.
control on form, text box, named "zctrltxtAllowAdmin" that only the admin can use.
Open your form in design view.
Right click on your control and select "properties" in the popup menu.
Select the "Other" tab in the properties.
In the list you will see a field named "Tag" (your it! ;-) ) this is where we'll use the group names (or the flags but that's much more complicated)
So in our example:
[zctrltxtAllowSome].[Tag] we will enter as a string:
"admin", "Spvsr", "Lead", "User"
[zctrltxtAllowAdmin].[Tag] we will enter as a string:
"admin"
You would do this for every control that you want to control user level access to.
Do not close; however, save your form.
Now before we go into the code, please read the thru the following... especially the first section:
> Before Posting (VBA or SQL) Code You need to understand how the Options work and the basic troubleshooting.
Now goto the "Event" tab of your form's property, the easy way to do this: Look at the property dialog, in the upper left corner is a drop down box, it should currently show the name of the control you're on (in our example, [zctrltxtAllowSome] or [zctrltxtAllowAdmin]) select the word "Form" in this box. You are now in the form's properties - click onthe "Event" tab.
Now look down this list, there will be one labeled "On Open" this is the very first event that "fires" when a form is opened, so click in the empty are for this field, you should see a dropdown arrow and a [...] button... click on the [...] and select "Code Builder"
The VBA editor will now open and you will get a blank:
- Option Compare Database
-
Option Explicit
-
-
Private Sub Form_Open(Cancel As Integer)
-
-
End Sub
-
From here, you will need to define a few variables to hold the user name, security group, and a pointer to the form (in our example "zfrmAlpha"
I can't tell you how to get the user name. This depends entirely on how you've set your login forms. Then I'd
dlookup()
to get the security group which for single hits is not too bad to use from a performance consideration.
Now that you have your security group, you would do a
For Each ctrlitem in zfrmAlpha.controls
to loop thru each control on the form, full the control's tag property, and do an instr compare aganst te return and unlock the control otherwise, so an "Admin" would be found in
[zctrltxtAllowSome] and in [zctrltxtAllowAdmin] ; however, "User" would only be found in [zctrltxtAllowSome].
Ok, back to the lab ;)