Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Object property/method problem
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 |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Object property/method problem
For the purposes of debugging and figuring out where in the line of code the
problem lies, break things up for a while until you isolate it: Dim anyText As String If TypeName(ctl) = "TextBox" Then anyText = Left(ctl.Text,2) anyText = cmbDrive.Text End If You've now broken it down into separate components, run it and see who breaks first. Also, I presume you've previously defined ctl ? "Ayo" wrote: 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 |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Object property/method problem
try this:
If TypeName(ctl) = "Textbox" Then If Left(ctl.Text, 2) = cmbdrive.text Then ....... End If End If "Ayo" wrote: 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 |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Object property/method problem
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 |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Object property/method problem
I think the problem is Left(ctl.Text,2). Everything else seem to to working
fine. So how would I compare the first 2 character in a TextBox control with the first 2 character in a ComboBox control? "JLatham" wrote: For the purposes of debugging and figuring out where in the line of code the problem lies, break things up for a while until you isolate it: Dim anyText As String If TypeName(ctl) = "TextBox" Then anyText = Left(ctl.Text,2) anyText = cmbDrive.Text End If You've now broken it down into separate components, run it and see who breaks first. Also, I presume you've previously defined ctl ? "Ayo" wrote: 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 |
#6
Posted to microsoft.public.excel.misc
|
|||
|
|||
Object property/method problem
I almost forgot, thanks for the help.
"JLatham" wrote: For the purposes of debugging and figuring out where in the line of code the problem lies, break things up for a while until you isolate it: Dim anyText As String If TypeName(ctl) = "TextBox" Then anyText = Left(ctl.Text,2) anyText = cmbDrive.Text End If You've now broken it down into separate components, run it and see who breaks first. Also, I presume you've previously defined ctl ? "Ayo" wrote: 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 |
#7
Posted to microsoft.public.excel.misc
|
|||
|
|||
Object property/method problem
Wow !!!. You are the man Chip. That was it. Thanks a lot.
"Chip Pearson" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA error: "object doesn't support this property or method" | Excel Discussion (Misc queries) | |||
How do I access to property of chart object ? | Charts and Charting in Excel | |||
Lookin property of the FileSearch object | New Users to Excel | |||
object reference does not support this property or method | Excel Discussion (Misc queries) | |||
Object doesn't support this property or method (Error 438) | Excel Discussion (Misc queries) |