I have two types of controls on my form: textboxes and combo boxes. My text boxes are all named in the format txt1, txt2, txt3...... Combo boxes are cbo1, cbo2, cbo3....
I have a button on the form that clears all values from both controls. The button is named cmdClear. The code is:
Code:
Private Sub cmdClear_Click()
Dim cControl As Control
For Each cControl In Me.Controls
If cControl.Name Like "txt*" Or cControl.Name Like "cbo*" Then cControl = vbNullString
Next
End Sub
The first code block works just fine but I am trying to refine the code to work for all controls.
Code:
Private Sub cmdClear_Click()
Dim cControl As Control
For Each cControl In Me.Controls
If cControl.Name Like "*" Then cControl = vbNullString
Next
End Sub
The second code block gives the following error:
"Run time error '5"
Invalid Procedure Call or Argument
Why am I getting this error?
I even tried:
Code:
Private Sub cmdClear_Click()
Dim cControl As Control
For Each cControl In Me.Controls
cControl = vbNullString
Next
End Sub
This code generated the same error. I am just removing the If statement so all contols should be assigned a null value. Any ideas? Thanks