Load form based on user group

K

Kay

Hi

I have set user groups on my database using the security feature
provided by Access2000. I want to display a form based on the user who
logs in. I have used the following code:

If CurrentUser() = "Admin" Then
DoCmd.OpenForm "ManagerOptions"
Else
If CurrentUser() = "Users" Then
DoCmd.OpenForm "UserOptions"
End If
End If

This works fine if I log in as admin as all the admins will login under
that username. But the group of users have their own login names so
using this code does not work for users. Does anyone know how I can get
it to load a form based on the group te user is part of.

Any help is very much appreciated
 
B

Barry Gilbert

This function might give you what you need:

Public Function IsUserInGroup(strUserName, strGroupName) As Boolean
On Error Resume Next
Dim strName As String
strName =
DBEngine.Workspaces(0).Users(strUserName).Groups(strGroupName).Name
IsUserInGroup = (Err.Number = 0)
End Function

HTH,
Barry
 
K

Kay

Do you know how I can use this function with my code as I have not
worked with functions

thanks
 
B

Barry Gilbert

If IsUserInGroup(CurrentUser(),"Admins") Then
DoCmd.OpenForm "ManagerOptions"
Else
If IsUserInGroup(CurrentUser(),"Users") Then
DoCmd.OpenForm "UserOptions"
End If
 
K

Kay

Do you know how I can use this function with my code as I have not
worked with functions

thanks
 
K

Kay

Thanks very much Barry, I really appreciate your help, It is now
working and all thanks to you

Thankyou
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top