Add format Condition

  • Thread starter Thread starter Roy Goldhammer
  • Start date Start date
R

Roy Goldhammer

Hello there

Is there a way to add format condition with vb code to all text boxes in
form?

any help would be useful
 
Thankes John for the article

But it doesn't take care of my problem:

I have and old application i converted from access97

In the new application i would like to add simple property:

If textbox or combobox gets the focus the control back color becomes yellow

I've tried this code?

Dim Frm As Form, ctl As Control
Dim str As String
Dim rst As DAO.Recordset
Dim fc As FormatCondition

DoCmd.SetWarnings True
Set rst = CurrentDb.QueryDefs("AllForms").OpenRecordset
With rst
While Not .EOF
If Not (!Name = "frmPr" Or !Name = "frmPrHaim") Then

DoCmd.OpenForm str, acDesign
Application.RefreshDatabaseWindow
strTxt = ""
For Each ctl In Forms(str).Controls
If TypeOf ctl Is TextBox Or _
TypeOf ctl Is ComboBox Then
If ctl.FormatConditions.Count = 0 Then
Set fc =
ctl.FormatConditions.Add(acFieldHasFocus, acEqual, "", "")
fc.BackColor = vbYellow
End If
End If
Next
DoCmd.Close acForm, str, acSaveYes
End If
.MoveNext
Wend
.Close
End With
Set rst = Nothing

What's wrong with this code?
 
Back
Top