I want to monitor when a value changes of several combo buttons on a user form. I have set this up using a class module to capture all the comboboxes on the userform. I have the following code in a class module called “ModComboClass”:
In the class module I am monitoring when a combo box value in the user form is changed, check the strEditMode variable value and update the CmdCancel button if strEditMode = “Yes”. The strEditMode variable is stored in the user form and changes depending on changes completed in the form. This value changes correctly from tests completed within the user form. However, when I go through the code step by step in the class module, it never picks up the value of strEditMode from the userform. I have added a debug.print strEditMode line of code before the value of strEditMode is checked in the class module but it comes back with nothing as if it checks but cannot obtain the value. Are there any restrictions within the class module that stops it obtaining the value of the strEditMode variable in the user form? Any help will be greatly appreciated.
The code for the code module “Userform1” is:
Code:
Public WithEvents ComboGroup As MSForms.ComboBox
Public Sub ComboGroup_Change()
If strEditMode = "Yes" Then 'editing a fixture mode
CmdCancel.Enabled = True
End If
End Sub
In the class module I am monitoring when a combo box value in the user form is changed, check the strEditMode variable value and update the CmdCancel button if strEditMode = “Yes”. The strEditMode variable is stored in the user form and changes depending on changes completed in the form. This value changes correctly from tests completed within the user form. However, when I go through the code step by step in the class module, it never picks up the value of strEditMode from the userform. I have added a debug.print strEditMode line of code before the value of strEditMode is checked in the class module but it comes back with nothing as if it checks but cannot obtain the value. Are there any restrictions within the class module that stops it obtaining the value of the strEditMode variable in the user form? Any help will be greatly appreciated.
The code for the code module “Userform1” is:
Code:
Dim strEditMode As String 'Confirm if in edit mode
Dim cCombo As Controls
Dim ModCombos() As New ModComboClass
Dim ModCombosCount As Integer
Private Sub UserForm_Initialize()
For Each cCombo In Me.Controls
If cCombo.Name Like "CboM_*" Then
ModCombosCount = ModCombosCount + 1 ‘Add 1 to no of comboboxes count
ReDim Preserve ModCombos(1 To ModCombosCount) ‘Reset ModCombo array
Set ModCombos(ModCombosCount).ComboGroup = cCombo ‘Add combobox to ComboGroup in class module
End If
Next cCombo
stEditMode = “No”
End Sub
Private Sub Cbo_Date_Change()
[Code added here for changes required within the form]
strEditMode = “Yes”
End Sub