village_alchemist
08-16-2004, 06:23 PM
Ok, this may be obvious, but if it weren't for you good folks here, I never would have found this. In fact, I've been searching through the help in Word 2000 and I *still* can't find reference to the TypeOf command. Is this some "top secret" Microsoft command, or is it in there somewhere and I just can't find it?
Now for the second - more curious question. In the following code, the textbox condition works, but the checkbox condition does not.
Dim ProjCtrl As Control
For Each ProjCtrl In frmItems.Controls
If TypeOf ProjCtrl Is TextBox Then
MsgBox ProjCtrl.Name, vbOKOnly, "Text Control Found"
ElseIf TypeOf ProjCtrl Is CheckBox Then
MsgBox ProjCtrl.Name, vbOKCancel, "Check Control Found"
End If
Next
However, when I put "MsForms." in front of the control type everthing works:
Dim ProjCtrl As Control
For Each ProjCtrl In frmItems.Controls
If TypeOf ProjCtrl Is MsForms.TextBox Then
MsgBox ProjCtrl.Name, vbOKOnly, "Text Control Found"
ElseIf TypeOf ProjCtrl Is MsForms.CheckBox Then
MsgBox ProjCtrl.Name, vbOKCancel, "Check Control Found"
End If
Next
I understand why it works with the MsForms in front, but could someone explain why without it the textbox works and the checkbox doesn't?
Now for the second - more curious question. In the following code, the textbox condition works, but the checkbox condition does not.
Dim ProjCtrl As Control
For Each ProjCtrl In frmItems.Controls
If TypeOf ProjCtrl Is TextBox Then
MsgBox ProjCtrl.Name, vbOKOnly, "Text Control Found"
ElseIf TypeOf ProjCtrl Is CheckBox Then
MsgBox ProjCtrl.Name, vbOKCancel, "Check Control Found"
End If
Next
However, when I put "MsForms." in front of the control type everthing works:
Dim ProjCtrl As Control
For Each ProjCtrl In frmItems.Controls
If TypeOf ProjCtrl Is MsForms.TextBox Then
MsgBox ProjCtrl.Name, vbOKOnly, "Text Control Found"
ElseIf TypeOf ProjCtrl Is MsForms.CheckBox Then
MsgBox ProjCtrl.Name, vbOKCancel, "Check Control Found"
End If
Next
I understand why it works with the MsForms in front, but could someone explain why without it the textbox works and the checkbox doesn't?