Use Variable from Public Function In If Statement

C

Casey

Hi,

Below I have a function that I have set in with the
class modules of my form as a public function. On this
form I have the fields [name1] and [group1]. Please don't
credit me with developing the structure of the function
because I received the framework of it in response to an
earlier newsgroup question.

I want to use the variable that is created by the
public function in an If statement within a Sub Procedure,
to determine whether a msgbox saying the "User has been
deleted from group." will show if the variable from the
public function is false. Nothing happens though. I am
presuming that the variable from the public function is
IIG.

I would appreciate any advice on this.

Thank you,

Casey


Directly below is the Function

Public Function IsInGroup(UsrName As String, GrpName As
String) As Boolean
Dim grp As Group
Dim IIG As Boolean
Dim usr As User

IIG = False
For Each usr In DBEngine.Workspaces(0).Users
If usr.Name = [Name1] Then GoTo FoundUser
Next
GoTo IIG_Exit
FoundUser:
For Each grp In usr.Groups
If grp.Name = [Group1] Then IIG = True
Next
IIG_Exit:
IsInGroup = IIG
End Function


Below here is the sub procedure

Private Sub Command174H_Click()
Dim ws As Workspace
Dim grpVp As Group, grpmanager As Group
Dim usr As User

Set ws = DBEngine.Workspaces(0)
Set grpmanager = ws.Groups([Group1])
grpmanager.Users.Delete ([Name1])
If IIG = false then
msgbox "User has been deleted from group."
Endif
End Sub
 
C

Casey

Thank you Lynn.

Casey
-----Original Message-----
Well, it doesn't appear that you actually make a call to the Function
IsInGroup. Try changing your Sub as below. (Warning! This is untested code.)

Private Sub Command174H_Click()
Dim ws As Workspace
Dim grpVp As Group, grpmanager As Group
Dim usr As User

Set ws = DBEngine.Workspaces(0)
Set grpmanager = ws.Groups([Group1])
grpmanager.Users.Delete ([Name1])
If IsInGroup(grpmanager,usr) = false then
msgbox "User has been deleted from group."
Endif
End Sub


--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm



Casey said:
Hi,

Below I have a function that I have set in with the
class modules of my form as a public function. On this
form I have the fields [name1] and [group1]. Please don't
credit me with developing the structure of the function
because I received the framework of it in response to an
earlier newsgroup question.

I want to use the variable that is created by the
public function in an If statement within a Sub Procedure,
to determine whether a msgbox saying the "User has been
deleted from group." will show if the variable from the
public function is false. Nothing happens though. I am
presuming that the variable from the public function is
IIG.

I would appreciate any advice on this.

Thank you,

Casey


Directly below is the Function

Public Function IsInGroup(UsrName As String, GrpName As
String) As Boolean
Dim grp As Group
Dim IIG As Boolean
Dim usr As User

IIG = False
For Each usr In DBEngine.Workspaces(0).Users
If usr.Name = [Name1] Then GoTo FoundUser
Next
GoTo IIG_Exit
FoundUser:
For Each grp In usr.Groups
If grp.Name = [Group1] Then IIG = True
Next
IIG_Exit:
IsInGroup = IIG
End Function


Below here is the sub procedure

Private Sub Command174H_Click()
Dim ws As Workspace
Dim grpVp As Group, grpmanager As Group
Dim usr As User

Set ws = DBEngine.Workspaces(0)
Set grpmanager = ws.Groups([Group1])
grpmanager.Users.Delete ([Name1])
If IIG = false then
msgbox "User has been deleted from group."
Endif
End Sub


.
 

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