Home All Groups Group Topic Archive Search About
Author
19 Jul 2006 7:40 PM
Olu Solaru
What is the proper Syntax for using the
IsUserInGroup Function in a Form's Open Event  Here is my current Syntax but
I am getting the following


error message: Expected End Sub

Private Sub Form_Load()

Function faq_IsUserInGroup(strGroup As String, strUser As String) As Integer
' Returns True if user is in group, False otherwise
' This only works if you're a member of the Admins group.

Dim ws As Workspace
Dim grp As Group
Dim strUserName As String

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.Groups(strGroup).Users(strUser).Name
faq_IsUserInGroup = (Err = 0)


If faq_IsUserInGroup("Regulatory", CurrentUser) Then
    Me.Add_Review_Employee_Information.Visible = True
    Me.cmdViewTraining.Visible = True
    Me.cmdReviseSops.Visible = True
    Me.cmdAddBpr.Visible = True
    Me.cmdRunReports.Visible = True
    Me.cmdAddLotNumber.Visible = True
    Me.cmdExit.Visible = True
Else
    Me.cmdAddLotNumber.Visible = True
    Me.cmdRunReports.Visible = True
    Me.cmdExit.Visible = True
End If
End Function
End Sub

Should the function be entered in as a Module in the Form Code?

Author
19 Jul 2006 7:58 PM
Joan Wild
See my answer in the original thread.

--
Joan Wild
Microsoft Access MVP

Olu Solaru wrote:
Show quoteHide quote
> What is the proper Syntax for using the
> IsUserInGroup Function in a Form's Open Event  Here is my current
> Syntax but I am getting the following
>
>
> error message: Expected End Sub
>
> Private Sub Form_Load()
>
> Function faq_IsUserInGroup(strGroup As String, strUser As String) As
> Integer ' Returns True if user is in group, False otherwise
> ' This only works if you're a member of the Admins group.
>
> Dim ws As Workspace
> Dim grp As Group
> Dim strUserName As String
>
> Set ws = DBEngine.Workspaces(0)
> Set grp = ws.Groups(strGroup)
> On Error Resume Next
> strUserName = ws.Groups(strGroup).Users(strUser).Name
> faq_IsUserInGroup = (Err = 0)
>
>
> If faq_IsUserInGroup("Regulatory", CurrentUser) Then
>    Me.Add_Review_Employee_Information.Visible = True
>    Me.cmdViewTraining.Visible = True
>    Me.cmdReviseSops.Visible = True
>    Me.cmdAddBpr.Visible = True
>    Me.cmdRunReports.Visible = True
>    Me.cmdAddLotNumber.Visible = True
>    Me.cmdExit.Visible = True
> Else
>    Me.cmdAddLotNumber.Visible = True
>    Me.cmdRunReports.Visible = True
>    Me.cmdExit.Visible = True
> End If
> End Function
> End Sub
>
> Should the function be entered in as a Module in the Form Code?