Add format Condition

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
 
R

Roy Goldhammer

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?
 

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