gcheatham
asked on
Enumerate the valid possible choices for control properties
Question:
I am using MS Access, but this may apply to VB as well.
Is there a way to enumerate the valid range of values for control properties?
I wanted to create a function to easily allow me to explore properties of any control, including activex controls, by looping through all the control properties, then for each property, place on the form the appropriate control filled with valid choices. So if the control property was BorderWIdth, a combo box might be added with all the available values for Border WIdth.
To test this out, I just need something like the following
For all the controls on this form 'I Already have this part
for all the properties of this control 'I already have this part
list the valid range of values for the property 'This is the part I need
Next
Next
So if the control property is BorderLineStyle, I know that is vbInteger, but I don't know what the valid entries are.
in other words, integer is -32k to +32k, but there are only a few choices for BorderLineStyle.
Another example, if the control property is BorderColor that is vbLong, but what are the valid ranges?
I am using MS Access, but this may apply to VB as well.
Is there a way to enumerate the valid range of values for control properties?
I wanted to create a function to easily allow me to explore properties of any control, including activex controls, by looping through all the control properties, then for each property, place on the form the appropriate control filled with valid choices. So if the control property was BorderWIdth, a combo box might be added with all the available values for Border WIdth.
To test this out, I just need something like the following
For all the controls on this form 'I Already have this part
for all the properties of this control 'I already have this part
list the valid range of values for the property 'This is the part I need
Next
Next
So if the control property is BorderLineStyle, I know that is vbInteger, but I don't know what the valid entries are.
in other words, integer is -32k to +32k, but there are only a few choices for BorderLineStyle.
Another example, if the control property is BorderColor that is vbLong, but what are the valid ranges?
It is worth noting that not all property values are available at all times. To overcome this a little error checking is in order. The example below simply skips over the occations where a value is not avail but with a little more detailed error checking you can be more specific on how you want to handel the cases where a value is not avail. For example some properties only have values when the control has the focus, others only have valus while the form is in design view, (that kind of thing). Anyway to get you going here you are....
Private Sub cmdGoForIt_Click()
On Error Resume Next
Dim frm As Form
Dim ctl As Control
Dim prp As Property
Set frm = Me
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print Space(5) & "Property Name: " & prp.Name
Debug.Print Space(10) & "Value: " & prp.Value
Next prp
Next ctl
End Sub
Private Sub cmdGoForIt_Click()
On Error Resume Next
Dim frm As Form
Dim ctl As Control
Dim prp As Property
Set frm = Me
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print Space(5) & "Property Name: " & prp.Name
Debug.Print Space(10) & "Value: " & prp.Value
Next prp
Next ctl
End Sub
here is a short code to place the form's/control's property to a text file
Sub getFormProp(sForm As String)
Application.SaveAsText acForm, sForm, "C:\Temp\" & "Form_" & sForm & ".txt"
End Sub
to use
getFormProp("NameOfForm")
Sub getFormProp(sForm As String)
Application.SaveAsText acForm, sForm, "C:\Temp\" & "Form_" & sForm & ".txt"
End Sub
to use
getFormProp("NameOfForm")
btw, that code also includes the codes behind the form
To include the sub forms one might modify the code as follows...
Private Sub cmdGoForIt_Click()
DisplayFormAndSubFormPrope rties Me
End Sub
Sub DisplayFormAndSubFormPrope rties(frm, Optional strLeadingSpaces = "")
On Error Resume Next
Dim frm As Form
Dim ctl As Control
Dim prp As Property
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print strLeadingSpaces & Space(5) & "Property Name: " & prp.Name
Debug.Print strLeadingSpaces & Space(10) & "Value: " & prp.Value
Next prp
If ctl.Type = Access.acSubform Then
Set frm = ctl.Form
strLeadingSpaces = strLeadingSpaces & Space(5)
DisplayFormAndSubFormPrope rties frm, strLeadingSpaces
End If
Next ctl
End Sub
Private Sub cmdGoForIt_Click()
DisplayFormAndSubFormPrope
End Sub
Sub DisplayFormAndSubFormPrope
On Error Resume Next
Dim frm As Form
Dim ctl As Control
Dim prp As Property
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print strLeadingSpaces & Space(5) & "Property Name: " & prp.Name
Debug.Print strLeadingSpaces & Space(10) & "Value: " & prp.Value
Next prp
If ctl.Type = Access.acSubform Then
Set frm = ctl.Form
strLeadingSpaces = strLeadingSpaces & Space(5)
DisplayFormAndSubFormPrope
End If
Next ctl
End Sub
Correction to my last post intended to include sub form properties....
Private Sub cmdGoForIt_Click()
DisplayFormAndSubFormPrope rties Me
End Sub
Sub DisplayFormAndSubFormPrope rties(frm, Optional strLeadingSpaces = "")
On Error Resume Next
Dim sfrm As Form
Dim ctl As Control
Dim prp As Property
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print strLeadingSpaces & Space(5) & "Property Name: " & prp.Name
Debug.Print strLeadingSpaces & Space(10) & "Value: " & prp.Value
Next prp
If (ctl.ControlType = Access.acSubform) Then
Set sfrm = ctl.Form
MsgBox sfrm.Name
strLeadingSpaces = strLeadingSpaces & Space(5)
DisplayFormAndSubFormPrope rties sfrm, strLeadingSpaces
End If
Next ctl
End Sub
Private Sub cmdGoForIt_Click()
DisplayFormAndSubFormPrope
End Sub
Sub DisplayFormAndSubFormPrope
On Error Resume Next
Dim sfrm As Form
Dim ctl As Control
Dim prp As Property
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print strLeadingSpaces & Space(5) & "Property Name: " & prp.Name
Debug.Print strLeadingSpaces & Space(10) & "Value: " & prp.Value
Next prp
If (ctl.ControlType = Access.acSubform) Then
Set sfrm = ctl.Form
MsgBox sfrm.Name
strLeadingSpaces = strLeadingSpaces & Space(5)
DisplayFormAndSubFormPrope
End If
Next ctl
End Sub
Correction to my last post intended to include sub form properties....
Private Sub cmdGoForIt_Click()
DisplayFormAndSubFormPrope rties Me
End Sub
Sub DisplayFormAndSubFormPrope rties(frm, Optional strLeadingSpaces = "")
On Error Resume Next
Dim sfrm As Form
Dim ctl As Control
Dim prp As Property
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print strLeadingSpaces & Space(5) & "Property Name: " & prp.Name
Debug.Print strLeadingSpaces & Space(10) & "Value: " & prp.Value
Next prp
If (ctl.ControlType = Access.acSubform) Then
Set sfrm = ctl.Form
strLeadingSpaces = strLeadingSpaces & Space(5)
DisplayFormAndSubFormPrope rties sfrm, strLeadingSpaces
End If
Next ctl
End Sub
Private Sub cmdGoForIt_Click()
DisplayFormAndSubFormPrope
End Sub
Sub DisplayFormAndSubFormPrope
On Error Resume Next
Dim sfrm As Form
Dim ctl As Control
Dim prp As Property
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print strLeadingSpaces & Space(5) & "Property Name: " & prp.Name
Debug.Print strLeadingSpaces & Space(10) & "Value: " & prp.Value
Next prp
If (ctl.ControlType = Access.acSubform) Then
Set sfrm = ctl.Form
strLeadingSpaces = strLeadingSpaces & Space(5)
DisplayFormAndSubFormPrope
End If
Next ctl
End Sub
Correction to my last post intended to include sub form properties (3rd time is the charm)....
Private Sub cmdGoForIt_Click()
DisplayFormAndSubFormPrope rties Me
End Sub
Sub DisplayFormAndSubFormPrope rties(frm, Optional strLeadingSpaces = "")
On Error Resume Next
Dim sfrm As Form
Dim ctl As Control
Dim prp As Property
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print strLeadingSpaces & Space(5) & "Property Name: " & prp.Name
Debug.Print strLeadingSpaces & Space(10) & "Value: " & prp.Value
Next prp
If (ctl.ControlType = Access.acSubform) Then
Set sfrm = ctl.Form
DisplayFormAndSubFormPrope rties sfrm, strLeadingSpaces & Space(5)
End If
Next ctl
End Sub
Private Sub cmdGoForIt_Click()
DisplayFormAndSubFormPrope
End Sub
Sub DisplayFormAndSubFormPrope
On Error Resume Next
Dim sfrm As Form
Dim ctl As Control
Dim prp As Property
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print strLeadingSpaces & Space(5) & "Property Name: " & prp.Name
Debug.Print strLeadingSpaces & Space(10) & "Value: " & prp.Value
Next prp
If (ctl.ControlType = Access.acSubform) Then
Set sfrm = ctl.Form
DisplayFormAndSubFormPrope
End If
Next ctl
End Sub
From what I've seen here thus far, the solutions proposed will not show you the range of values of the property of the control on a form - just the value for that particular form. I do not believe there is a way to access this range via VBA in Access.
A form has a textbox control. The control has the property Border width. The values possible are Hairline, 1 pt, 2 pt, 3 pt, 4 pt, 5 pt, and 6 pt. Intellisense will often give the permissable values, but if they are not listed in the Object Browser, you will not see them using Intellisense as in this case.
A form has a textbox control. The control has the property Border width. The values possible are Hairline, 1 pt, 2 pt, 3 pt, 4 pt, 5 pt, and 6 pt. Intellisense will often give the permissable values, but if they are not listed in the Object Browser, you will not see them using Intellisense as in this case.
ASKER
All replies are appreciated, by GRayL is correct. None of the solutions gives the possible valid values that could be assigned to the control property. THe object browser lists Enum properties for access controls and ActiveX controls, so the Enum "property" for a given control in the Object Browser shows the possible choices. I know there is a dll that comes with VB6 that may do what I want, but there must be a way to access the possible valid values for a control property like the Object Browser does. Anyone have any ideas? My intention is to be able to quickly stick the Control Name, Property Name and Possible Values into a table, so I can have a "property sheet" that I can play with at runtime to see which options work / look the best.
ASKER
Also, there may be a way to do it if there is a trappable error if you try to assign or get a property value that isn't valid.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Let me try this out, I will be back in a day or two, if it works, then I will award points to danaseaman, and then I might have another 500 point related question.
Private Sub cmdGoForIt_Click()
Dim frm As Form
Dim ctl As Control
Dim prp As Property
Set frm = Me
For Each ctl In frm.Controls
Debug.Print "Control Name: " & ctl.Name
For Each prp In ctl.Properties
Debug.Print Space(5) & "Property Name: " & prp.Name
Next prp
Next ctl
End Sub