Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to know the Group name of the user

Status
Not open for further replies.

Vandys

IS-IT--Management
Aug 3, 2000
29
AU
Hi all,

I have forms in which there are many commandbuttons or text boxes which should be visible depending upon the group to which the user belongs. For example, if the user belongs to the cashier group, then the buttons #3 and #4 should be visible and if the user belongs to the "admin" group then the admin buttons (# 5 and 6) should become visible.

Can you please help me in finding the group name from the user's name?

Regards,

Vandy :-0 [sig][/sig]
 
Try the following code, I found it in the Code-Librarian, so I'm not sure if it works or not. I've not tried opening the mdw before!!

Code:
Function UserInGroup(UName As String, GName As String) As Integer
Code:
'
' Checks whether the user name specified belongs to the group
' name specified.  This is specific to the current system.mdw only.
'
Code:
Dim w As DAO.Workspace, U As DAO.User, i As Integer, Found As Integer
  UserInGroup = False
  Set w = DBEngine.CreateWorkspace("", "Admin", "")
Code:
' 2nd arg=Admins level user name, 3rd=Password
'
' Checks if user name is valid for this system.mdw
'
Code:
  Found = False
  For i = 0 To w.Users.Count - 1
    If w.Users(i).Name = UName Then
      Found = True
      Set U = w.Users(i)
      Exit For
    End If
  Next i
  If Not Found Then
     MsgBox "User '" & UName & "' is not a valid user name."
     Exit Function
  End If
Code:
'
' Check if user is in the group
'
Code:
  For i = 0 To U.Groups.Count - 1
    If U.Groups(i).Name = GName Then
      UserInGroup = True
      Exit Function
    End If
  Next i
End Function
[sig]<p>Phooey<br><a href=mailto:Andrew.j.harrison@capgemini.co.uk>Andrew.j.harrison@capgemini.co.uk</a><br>Otherwise known as Windy Bottom.[/sig]
 
Another way to go would be to use a case statement.

Example

Select case group
case cashier
btn3.visible = true
btn4.visible = true
btn5.visible = false
btn6. visible = false
case admin
btn5.visible=true
btn6.visible=true
btn3.visible = false
btn4. visible = false
end select



All you do is substitute the name group, for the field that you are using as the criteria field. Then use the case names as possible values in the field. If the values for the field, and the case names are going to be text (Admin, Cashier) then make sure to use quotations around the name.

Example


Select case group
case &quot;ADMIN&quot;


It is a little easier to do it this way than the one above, and I know that it will work. There is probably a better way to do it, but this one works. [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top