Is it possible to Enumerate the properties collection of a Control? (1 Viewer)

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 20:17
Joined
Jul 9, 2003
Messages
16,282
The commented out part of code is from MS Access help and works OK.

The part below that is my attempt at extracting (enumerating) through the properties of a control. It doesn't work! Seems to me that I've had problems with this before, and my suspicion is that it's not possible, however I thought I would ask here.

The simple question is:

Is it possible to examine the properties of a control as a "collection"?

Your thoughts and observations appreciated.... (more information below if anyone is interested)


Code:
''    Dim frm As Form, prp As Property
''
''    ' Enumerate Forms collection.
''    For Each frm In Forms
''        ' Print name of form.
''       MsgBox " >>> " & frm.Name
''        ' Enumerate Properties collection of each form.
''        For Each prp In frm.Properties
''            ' Print name of each property.
''            If Left(prp.Name, 1) = "p" Then
''            MsgBox " >>> " & prp.Name & " = " & prp.Value
''            End If
''        Next prp
''    Next frm
    
    
   Dim Ctrl As Control
    Dim prp As Property

        For Each prp In cboDefaults

            MsgBox " >>> " & prp.Name '& " = " & prp.Value

        Next prp

I have passed the "instance?" of a control from one form (calling form) to another (called form). I pass it into a custom property in the other form (again called form) .

I now want to display the information within that control (a combo box) on another combo box displayed on my form (the called form). So in effect I need to set the properties of the combo box on the "called form" to the same as the combo box on the calling form".



I believe this would be a simple matter if I could access the properties collection of the control, and also the properties collection of the custom property. But I don't think it's possible.

I have thought of a way round the problem, I will extract that property names individually into an array, and then individually set them there. Then pass the values back into the control. This seems a bit long winded, I wondered if anyone had any observations before I embark on this tortuous project.
 

pono1

Registered User.
Local time
Today, 12:17
Joined
Jun 23, 2002
Messages
1,186
Is it possible to examine the properties of a control as a "collection"?


Code:
'

        Dim prp As Property
        For Each prp In cboDefaults.[COLOR="Red"]Properties[/COLOR]

            MsgBox " >>> " & prp.Name '& " = " & prp.Value

        Next prp

Regards,
Tim
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 20:17
Joined
Jul 9, 2003
Messages
16,282
Thanks Tim, that one had me scratching my head!
 
Last edited:

pono1

Registered User.
Local time
Today, 12:17
Joined
Jun 23, 2002
Messages
1,186
Not a problem. Were you able to capture the property's value as well as the name?

Regards,
Tim
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 20:17
Joined
Jul 9, 2003
Messages
16,282
All except one property which threw an error, said you need to "setfocus" to the control before examining the property, haven't looked into it yet, will probably just isolate the property from the loop.

Thanks again to help Tim. Cheers Tony
 

Banana

split with a cherry atop.
Local time
Today, 12:17
Joined
Sep 1, 2005
Messages
6,318
I wonder if that one was "Text", as others has posted that this requires a focus.

I suppose one could get the current control in focus, and hold it in a variable, set the focus to the control being investigated for that property, then when the function is done, return the focus to original control prior to calling the function.
 

Users who are viewing this thread

Top Bottom