Prpery of a control

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

Guest

Hi

On my form i have a text box, which shows the user name. I need to change
the property(visible=yes or no) of few controls based on the user names. We
are 8 users are using the access file. i need to show few controls to 3 uers
and another few conrols to another 3 users and so on....

how do i do this, please provide a code
 
Hi,

Many ways to skin a cat but here goes:

In the text box AfterUpdate Event:

Select Case txtUserName 'Change with the name of your text box
Case "Joe Bloggs", "Joan Bloggs"
ctlName1.Visible = False
ctlName2.Visible = True
Case "John Doe", "Julie Doe"
ctlName1.Visible = True
ctlName2.Visible = False
End Select

--
HTH

Mark Phillipson

Free Add-Ins at; http://mphillipson.users.btopenworld.com/
 
DON'T hard-code the usernames in your code. This means if you need to
change the usernames or their level oc access, you must edit your code.
Instead, here is a simple solution:

Create a table (tblUsers) with two fields: UserName (text, primary key) and
a Yes/No field PowerUser (or whatever).

In your Form_Load event procedure:

Dim fPowerUser as Boolean
fpowerUser = Nz(DLookup("PowerUser", "tblUsers", _
"UserName='" & CurrentUser & "'"), False)
Me.Control1.Visible = fPowerUser
Me.Control2.Visible = fPowerUser
.... etc

A better solution would be to use the Groups facility in Access security to
assign the users to different groups. The following function will return
True if a user is in a given group:

Public Function IsUserInGroup(sGroup As String, _
Optional ByVal sUser As String) As Boolean
Dim grp As Group
On Error Resume Next
If Len(sUser) = 0 Then sUser = CurrentUser
Set grp = DBEngine(0).Users(sUser).Groups(sGroup)
If Err Then
Err.Clear
Else
Set grp = Nothing
IsUserInGroup = True
End If
End Function

You can then say:

Me.Control1.Visible = IsUserInGroup("Admins")
Me.Control2.Visible = IsUserInGroup("Sales")
....etc

As a user can be in more than one group, this would give you great
flexibility, and is very easy to manage.
 
Back
Top