Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default 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   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default 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   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA error: "object doesn't support this property or method" Dave F Excel Discussion (Misc queries) 2 April 23rd 07 06:04 PM
How do I access to property of chart object ? HP. Jung Charts and Charting in Excel 0 April 11th 07 02:36 PM
Lookin property of the FileSearch object [email protected] New Users to Excel 0 December 5th 06 09:37 PM
object reference does not support this property or method [email protected] Excel Discussion (Misc queries) 2 June 14th 06 07:23 PM
Object doesn't support this property or method (Error 438) Kiran Excel Discussion (Misc queries) 1 July 12th 05 08:42 PM


All times are GMT +1. The time now is 01:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"