Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Formating and Repainting the Form

Status
Not open for further replies.

SirTECH

Technical User
Jul 24, 2005
42
CA
I have a continuous form that I want to use conditional formating.
Field1 would use one set of conditional formating.
Field2 would use a different set of conditional formating.
The conditional formating I use works - well, kind of.
After requerying the form, the form flickers, and the fields repaint/refresh only after I run the mouse over it. I understand that the problem may lie with using conditional formating with continuous forms, so I thought about using vba instead, but am unsure how to do so with different types of controls (one is a combobox and one is text).
Will something like this work.... (please feel free to offer additional code to make it work).

For each Control in Form
If {condition} then Control1.backcolor = vbBlue
If {condition} then Control2.backcolor = vbRed
Next

I need to use conditional formating, so any work around would appreciated.
 
I found this somewhere:

Code:
Function ConvertLabelOnTabPage(strFormName As String, _
        Optional bSaveAndClose As Boolean, Optional bHidden As Boolean)
    'Purpose:   Change unattached labels on pages of tab control into text boxes.
    '           Avoids flicker bug under Windows XP themes.
    Dim frm As Form
    Dim ctl As Control
    Dim strName As String
    Dim strCaption As String
    Dim bytBackStyle As Byte
    Dim bChanged As Boolean
    Const strcQuote = """"
    
    'Open the form in design view
    DoCmd.OpenForm strFormName, acDesign, _
        WindowMode:=IIf(bHidden, acHidden, acWindowNormal)
    Set frm = Forms(strFormName)
    
    'Find the labels whose parent is a tab page.
    For Each ctl In frm.Controls
        If ctl.ControlType = acLabel Then
            If ParentIsTabPage(ctl) Then
                bChanged = True
                strName = ctl.Name           'ctl reference will be lost.
                strCaption = ctl.Caption     'For ControlSource.
                bytBackStyle = ctl.BackStyle 'Access doesn't set this.
                Debug.Print strFormName & "." & strName
                'Convert it to a text box.
                ctl.ControlType = acTextBox
                'Set the text box properties.
                With frm.Controls(strName)  'ctl is now undefined.
                    .ControlSource = "=" & strcQuote & _
                        Replace(strCaption, strcQuote, strcQuote & strcQuote) & strcQuote
                    .Enabled = False
                    .Locked = True
                    .BackStyle = bytBackStyle
                End With
            End If
        End If
    Next
    
    Set ctl = Nothing
    Set frm = Nothing
    If Not bChanged Then
        DoCmd.Close acForm, strFormName, acSaveNo
    ElseIf bSaveAndClose Then
        DoCmd.Close acForm, strFormName, acSaveYes
    End If
End Function

Pampers [afro]
Keeping it simple can be complicated
 
Thanks for your suggestion. I actually found a fix for it by changing the affected fields.
Originally the field I wanted to apply a conditional format had as its control source a DLookup("field","table",
"criteria"). I moved the DLookup to the root query I was using for this form. Since doing that, the flicker and form refreshing has been corrected.
Thanks again for your reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top