[RESOLVED] User Defined Classes and Collections - Event Procedures
Is it possible to call an event procedure based on the value of a property in a user defined class?
I have a class "MyUser" and an associated collection "MyUsers". The MyUser object has a Boolean property call "Active".
What I would like to do is call an Event Proc (UserActivate) in the collection class, whenever an instance MyUser has its Active property set to TRUE that sets all the Active property of all other instances of MyUser in MyUsers to FALSE.
I currently have a sub that checks for this, but I need to call it any time something changes in the active instance of MyUsers. I would like to have this fire automatically any time the property changes.
Code snippets attached:
VB Code:
'From the MyUser Class Module
Private pActive As Boolean
Public Property Get Active() As Boolean
Active = pActive
End Property
Public Property Let Active(iActive As Boolean)
pActive = iActive
End Property
'From the MyUsers Class Module
Private pMyUsers As Collection
Public Function Add(FullName As String, EMail As String, Active As Boolean)
Dim NewUser As MyUser
Dim Key As Variant
With NewUser
.FullName = FullName
.EMail = EMail
.Active = Active
Key = .FullName
End With
' add to the private collection
pMyUsers.Add NewUser, Key
Set Add = NewUser
Function_Exit:
Set NewUser = Nothing
End Function
'The following snipped are from my regular modules
'Object vailables used throughout my code
Dim TestUsers As MyUsers
Dim TestUser As MyUser
' This is the sub I call repeatedly to change the active flag on all users other than the active user
Sub ChangeActive(ActiveUser As MyUser)
Dim OtherUser As MyUser
For Each OtherUser In TestUsers
If OtherUser.FullName <> ActiveUser.FullName Then
OtherUser.Active = False
End If
Set OtherUser = Nothing
End Sub
Re: User Defined Classes and Collections - Event Procedures
with events (you'll need to read up on it).
I think you can only call it from a form and I dunno if VBA supports it fully.
On the forms module you can define the class and use with events to have events on it. In the class you need to have an event (public I think) that matches. Should be some info on ms site or in the help files.
Re: User Defined Classes and Collections - Event Procedures
Great, there is some stuff in the help files on this.
Thanks for the direction.