-
AfterUpdate event in Class module
Hi,
I have some classes for controls. My combobox class has an afterUpdate event that doesn't run. Change event works fine but AfterUpdate is just ignored. some of the comboboxes already have afterupdate events (was going to exclude them from the class) would this be the reason why none of the AfterUpdate events fire or is it just not recognized as an event? Doesn't make sense to me.
Class Module:
[vba]Option Explicit
Public WithEvents cbCtrls As msforms.ComboBox
Private cmbName As String
Private essential As Boolean
Property Let isEssential(yesNo As Boolean)
essential = yesNo
End Property
Property Get isEssential() As Boolean
isEssential = essential
End Property
Property Let Name(str As String)
cmbName = str
End Property
Property Get Name() As String
Name = cmbName
End Property
Private Sub cbCtrls_AfterUpdate()
MsgBox "Work dammit!"
End Sub
Public Sub Delete()
cbCtrls.Text = ""
End Sub[/vba]
Initialising:
[vba]Public Sub comboBoxClass_Initialise()
Dim ctrl As Control
Dim X As Long
Dim thisCtrl As String
comboCount = 0
For Each ctrl In UserForm1.specFrame.Controls
If TypeName(ctrl) = "ComboBox" Then
thisCtrl = ctrl.Name
comboCount = comboCount + 1
ReDim Preserve combo_box(1 To comboCount)
With combo_box(comboCount)
Set .cbCtrls = ctrl
.Name = thisCtrl
Select Case (thisCtrl)
Case "cmbTSize"
.isEssential = True
Case "cmbPaperType"
.isEssential = True
Case "cmbType"
.isEssential = True
Case Else
.isEssential = False
End Select
End With
End If
Next
End Sub[/vba]
-
Glen,
I can't get this code to work. I just run into one error after another.
Can you post your workbook?
-
No, I really can't. I'll cut the code down.
Standard Module code:
[vba]Public Sub comboBoxClass_Initialise()
Dim ctrl As Control
Dim X As Long
Dim thisCtrl As String
Dim comboCount As Long
comboCount = 0
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "ComboBox" Then
thisCtrl = ctrl.Name
comboCount = comboCount + 1
ReDim Preserve combo_box(1 To comboCount)
With combo_box(comboCount)
Set .cbCtrls = ctrl
.Name = thisCtrl
.isEssential = True
End With
End If
Next
End Sub[/vba]
-
I forgot, setting combo_box:
[vba]Global combo_box() As New clsComboBoxes[/vba]
-
That is where I am getting the problems.
Combo_box is declared, I assumed an array, but this line fails
[vba]ReDim Preserve combo_box(1 To comboCount)[/vba]
and even if I declare it up front, this line fails
[vba]Set .cbCtrls = ctrl[/vb]
what dot properties does an array have?
-
Cheers for having a look Bob.
Combo_Box is the class instance
-
Can't get past it, I get an error on this line
ReDim Preserve combo_box(1 To comboCount)
How can you redim a class instance?
-
Not sure if I'm using the right term (instance).
[VBA]Global combo_box() As New clsComboBoxes[/VBA]
clsComboBoxes is the name of my class module, the first lot of code in post #1. The second lot of code is in a standard module and it all works fine for me except the AfterUpdate event. When I substitute Change for AfterUpdate the message box shows up after a change in any combo box.
Sorry, don't know a hell of a lot about classes in VBA so I can't say why the redim works (or doesn't in your case).
I'm using Excel 2003 if that explains anything.
-
Sorry, I am being a bit slow today.
I can see now that Combo_Box is an array of the class instances. I just added a Redim Combo_Box (1 to 1) upfront.
The problem is that the AfterUpdate event isn't exposed in a control array of this type. You can see this if you go into your class, delete that cbCtrls_AfterUpdate procedure, then select cbCtrls from the General dropdown, then select the dropdown from the Declarations list. You will see that there is no AfterUpdate event. Sorry, just can't do it.
-
Oh well, I can use the Change event so that's good enough. Thanks for your time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules