Controls are contained in the Controls collection much the same way an open
form is contained in the Forms collection. You'll need to add the statement
Dim ctl as Control in your code if you have Option Explicit turned on. Use
"For Each ctl in frm.Controls" to loop through all controls in the form and
then another nested For...Each to loop through all the properties in
clt.Properties collection.
Be careful to trap for errors!
In some cases, a control does not have some properties or events ascotiated
to it. Looping in this manner will also include form sections, labels,
lines, ect.
Perhaps use Select Case ctl.ControlType to determine if it is the type of
control that you need to set properties on. Some properties may require
others to be set in a specific manner such as WhatsThisButton - this cannot
be set unless MinMaxButtons is set to None.
Remember to close the form saving changes.
Mike Storr
www.veraccess.com
"deko" <dje422@hotmail.com> wrote in message
news:NATNb.11609$as6.11007@newssvr27.news.prodigy. com...[color=blue]
> I'm trying to find a way to set form/control properties programmatically.
>
> In a nut shell:
>
> 1. Open a database
> 2. Open a form in design view
> 3. Do something like this:
> For Each prp In frm.Properties
> If prp.Name = rst!PropName Then
> prp = rst!ChangeTo
> End If
> Next
>
> (this actually works for Form properties)
>
> BUT .. I'm having a hard time with the Control properties...
>
> How to access the properties of controls programmatically?
>
> here is more code....
>
> 'first, open the database in question
>
> Dim frm As Form
> Dim prp as Property
> Dim acc As Access.Application
> Set acc = CreateObject("Access.Application")
> acc.OpenCurrentDatabase varPath
>
> ''''''''''then open the form in design view
>
> acc.DoCmd.OpenForm rst!ObjectName, View:=acDesign, WindowMode:=acHidden
>
> '''''''''''now access the forms collection (I think that's what this
> does...)
>
> Set frm = acc.Forms(strFormName)
>
> ''''''''''''''''this is where I get lost...
>
> For Each ctl In frm.Controls
>
> '''''''''''''do I need For ... Each if I know what I'm looking for?
>
> If ctl = acCommandButton Then 'error: This property isn't available in
> design view
> For Each prp In ctl.Properties
> Debug.Print prp.Name & " = " & prp.Value
> prp = rst!ChangeTo <<== rst has all the ChangeTo values
> Debug.Print prp.Name & " = " & prp.Value
> Debug.Print ctl.Name & " changed"
> Next
> End If
> Next
>
>[/color]