LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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


 
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 12:47 PM.

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

About Us

"It's about Microsoft Excel"