Hi, this is my first time posting. I have searched the internet for 2 days and still can't figure this out. I have a form that has option buttons and text boxes. When the user clicks a label with the caption "clear all entries", the option buttons are deselected, and the text boxes are cleared of any entries. When the form initializes, the option buttons and text boxes are put into a user defined collection. The code to deselect and clear the controls is in a class module named clsFormEvents. The problem is: the option button part works fine, but the text box gives me Runtime error "13" Type Misatch when it gets to the line to add it to the collection. I don't see anything wrong. Here's the code for creating the collection:
This code is behind the userform
Dim col_Selection As New Collection
Private Sub UserForm_Initialize()
Dim ctl1 As MSForms.OptionButton
Dim ctl2 As MSForms.TextBox
Dim optb_ctl1 As clsFormEvents
Dim tbox_ctl2 As clsFormEvents
'go thru the members of the frame and add them to the collection
option buttons:
[For Each ctl1 In Frame2.Controls
Set optb_ctl1 = New clsFormEvents
Set optb_ctl1.optb = ctl1
col_Selection.Add optb_ctl1
Next ctl1
textboxes:
For Each ctl2 In Frame1.Controls
Set tbox_ctl2 = New clsFormEvents runtime error "13"
Set tbox_ctl2.tbox = ctl2
col_Selection.Add tbox_ctl2
Next ctl2
End Sub
Here is the code that resides in a class module named clsFormEvents
Option Explicit
Public WithEvents optb As MSForms.OptionButton
Public WithEvents tbox As MSForms.TextBox
Public Sub UnselectAll()
optb.Value = False
tbox.Value = " "
End Sub
If anyone can tell me why the text box gives this error, I would be ever so grateful. I don't see anything wrong with it and have searched the internet for some ideas, but none have surfaced. Thanks in advance.
This code is behind the userform
Dim col_Selection As New Collection
Private Sub UserForm_Initialize()
Dim ctl1 As MSForms.OptionButton
Dim ctl2 As MSForms.TextBox
Dim optb_ctl1 As clsFormEvents
Dim tbox_ctl2 As clsFormEvents
'go thru the members of the frame and add them to the collection
option buttons:
[For Each ctl1 In Frame2.Controls
Set optb_ctl1 = New clsFormEvents
Set optb_ctl1.optb = ctl1
col_Selection.Add optb_ctl1
Next ctl1
textboxes:
For Each ctl2 In Frame1.Controls
Set tbox_ctl2 = New clsFormEvents runtime error "13"
Set tbox_ctl2.tbox = ctl2
col_Selection.Add tbox_ctl2
Next ctl2
End Sub
Here is the code that resides in a class module named clsFormEvents
Option Explicit
Public WithEvents optb As MSForms.OptionButton
Public WithEvents tbox As MSForms.TextBox
Public Sub UnselectAll()
optb.Value = False
tbox.Value = " "
End Sub
If anyone can tell me why the text box gives this error, I would be ever so grateful. I don't see anything wrong with it and have searched the internet for some ideas, but none have surfaced. Thanks in advance.