Ayo,
In
VB/VBA, both halves of an AND statement are evaluated. This means that
the second half is evaluated even if the first half is False. Therefore,
Left(ctl.Text, 2) = cmbDrive.Text
is evaluated even if
TypeName(ctl) = "TextBox"
is False.
Thus, if ctl is not a textbox (or another control that has a Text property),
you'll get the error when attempting to read the Text property of ctl.
Instead of AND, use
If TypeName(ctl) = "TextBox" Then
If Left(ctl.Text,2) = cmbDrive.Text Then
This ensures that ctl is a TextBox prior to checking the Text property.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
"Ayo" wrote in message
...
Can anyone tell me what is wrong with this code. I keep getting "Object
doesn't support this property or method" error message and I can't figure
out
wish object.
If TypeName(ctl) = "TextBox" And Left(ctl.Text, 2) = cmbDrive.Text Then