Print Conditional Formatting

G

Gitche Gumee

How can I print all the conditional formatting for the controls on a form?
 
D

dch3

Sub snoopFormatConditions()

Set frm = Forms("frmTrailerDispatch")

For i = 0 To frm.Controls.Count - 1
Set ctl = frm.Controls(i)
With ctl
Debug.print
"--------------------------------------------------------------"
Debug.Print .Name, .ControlType
If .ControlType = acComboBox Or .ControlType = acTextBox Then
For j = 0 To .FormatConditions.Count - 1
Debug.Print .FormatConditions(j).Expression1
Debug.Print .FormatConditions(j).Expression2
Debug.Print .FormatConditions(j).Enabled
Debug.Print .FormatConditions(j).ForeColor
Debug.Print .FormatConditions(j).BackColor
Next j
End If
End With
Next i

Set frm = Nothing

End Sub

For the code to work, you'll need to have the form open as if you're
adding/editing records. There are several properties invovled as well such as
..Enabled, .BackColor, .ForeColor and I think two others. Check VBA Help under
FormatCondition Object for the specifics.
 
G

Gitche Gumee

Thanks! That's just what I needed.

dch3 said:
Sub snoopFormatConditions()

Set frm = Forms("frmTrailerDispatch")

For i = 0 To frm.Controls.Count - 1
Set ctl = frm.Controls(i)
With ctl
Debug.print
"--------------------------------------------------------------"
Debug.Print .Name, .ControlType
If .ControlType = acComboBox Or .ControlType = acTextBox Then
For j = 0 To .FormatConditions.Count - 1
Debug.Print .FormatConditions(j).Expression1
Debug.Print .FormatConditions(j).Expression2
Debug.Print .FormatConditions(j).Enabled
Debug.Print .FormatConditions(j).ForeColor
Debug.Print .FormatConditions(j).BackColor
Next j
End If
End With
Next i

Set frm = Nothing

End Sub

For the code to work, you'll need to have the form open as if you're
adding/editing records. There are several properties invovled as well such as
.Enabled, .BackColor, .ForeColor and I think two others. Check VBA Help under
FormatCondition Object for the specifics.
 
D

dch3

You may want to keep it handy as I've had to snoop the controls & their
properties on multiple occasions. Just remove the For J Next Loop and replace
it with the property that your snooping such as .controlSource or .tag.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top