Object doesn't support this property or method

Derek

Registered User.
Local time
Today, 01:18
Joined
May 4, 2010
Messages
234
I am getting Object doesn't support this property or method error at red font line. I just want to check through loop that if all the controls are null or not. Any help will be much appreciated.
Code:
 For Each ctr In Me.Controls
    
    [COLOR=red]If ctr.Value = "" Then
[/COLOR]       i = i + 1
    End If
Next ctr
 
not all controls have values...labels no.
you should specify what controls
if typename(ctl)= "textbox" then
 
Thanks. It worked.
 
It adds a bit of overhead, but when I do when looking at specific properties in a scan like this is

Code:
Public Function boCtlHasProp( byVal oX as Object, sPName as String ) as Boolean

Dim Sx as String
Dim HasIt as Boolean

    On Error Goto CHP_No                                    'Set a trap
    sX = CStr( NZ( ox.Properties( sPName, "" ) )    'Try to get property value
    HasIt = True                                                  'If no trap, we got the property
    GoTo CHP_Done
CHP_No:
    HasIt = False                                                  'trap stopped us - no such property
    Resume CHP_Done

CHP_Done:
    boCtlHasProp = HasIt                                       'return True if have this property

End Function

Put this function in a general module so that the Public declaration actually IS public (It isn't when placed in a Class Module). Now, your code becomes

Code:
    For Each ctr In Me.Controls

    if boCtlHasProp( ctr, "Value" ) then
        If ctr.Value = "" Then
           i = i + 1
        End If
    End if

Next ctr

This works for any property that I have run across so far.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom