typeof issue (VBA)

  • Thread starter Thread starter Edson
  • Start date Start date
E

Edson

Guys,

I've wrote the following code in order to clean a form:

Private Sub cmdCancel_Click()
For Each C In Form1.Controls
If TypeOf Control Is TextBox Then
C.Value = Null
ElseIf TypeOf C Is ComboBox Then
C.ListIndex = -1
End If
Next
End Sub

This code works *ONLY* for ComboBox type, and ignore all textboxes (the
contents aren't cleaned).
Where I'm wrong?
 
Try:
If TypeOf Control Is msforms.TextBox Then

There's a textbox on the Drawing toolbar that gets top priority.

I'd use:
ElseIf TypeOf C Is msforms.ComboBox Then
too.
 
Hi Edson
Amend
If TypeOf Control Is TextBox Then
To
If TypeOf C Is TextBox Then

Since you are using the variable C in your For Each loop.

HTH
Cordially
Pascal
 
ps...

If TypeOf C Is msforms.TextBox Then

I missed that you used Control on that first line.
 
Thanks, Dave,
your suggestion worked perfectly.
(in time, I've mistyped the variabel "Control" in my post, but in the real
code "C" only)
 
Back
Top