typeof issue (VBA)

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?
 
D

Dave Peterson

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.
 
P

papou

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
 
D

Dave Peterson

ps...

If TypeOf C Is msforms.TextBox Then

I missed that you used Control on that first line.
 
E

Edson

Thanks, Dave,
your suggestion worked perfectly.
(in time, I've mistyped the variabel "Control" in my post, but in the real
code "C" only)
 
Top