2016-04-29 5 views
0

Ich habe ein Testformular mit einem einzigen Kombinationsfeld, in dem ich eine bedingte Formatierung basierend auf der Option im Feld ausgewählt habe. Das Kombinationsfeld hat das Tag "Conditional".Kann bedingte Formatierung in Access 2013 nicht löschen

Um die bedingte Formatierung zu ändern, habe ich ein Sub-Formular geöffnet. In Zukunft wird dies auf viele Kombinationsfelder mit dem Tag "Conditional" angewendet.

Private Sub ApplyCondFormatting() 
    Dim objFrc As FormatCondition 
    Dim ctl As Control 

    For Each ctl In Me.Controls 
     If ctl.Tag = "Conditional" Then 
      With ctl 
       'Remove format conditions 
       .FormatConditions.Delete 
       MsgBox ("Test") 

       'Apply new format conditions 
       Set objFrc = .FormatConditions.Add(acExpression, acEqual, "[Value] = Correct") 
       Set objFrc = .FormatConditions.Add(acFieldValue, acEqual, "[Value] = Incorrect") 

       'Specify the formating conditions 
       .FormatConditions(0).BackColor = RGB(0, 255, 0) 
       .FormatConditions(0).Enabled = True 
       .FormatConditions(1).BackColor = RGB(255, 0, 0) 
       .FormatConditions(1).Enabled = True 
      End With 
     End If 
    Next ctl 
    Set objFrc = Nothing 
End Sub 

Die MsgBox erscheint, so das Makro ist ordnungsgemäß ausgeführt, aber es wird nicht gelöscht, die alte oder die neue Formatierung hinzuzufügen. Was vermisse ich?

Antwort

1

Dies sollte funktionieren, aber es gilt nur "vorübergehend" auf das derzeit geöffnete Formular.

Wenn Sie es dauerhaft machen wollen, müssen Sie das Formular in Ansicht Design öffnen vorher

DoCmd.OpenForm strMyForm, acDesign 

und speichern Sie es danach

DoCmd.Save acForm, strMyForm 
+0

Gibt es eine Möglichkeit, dies ohne Öffnung zu tun Designansicht? Mein Code wird ausgeführt, wenn der Benutzer eine Schaltfläche drückt. – jjjjjjjjjjj

+0

@jjjjjjjjjj: Vielleicht müssen Sie Ihre Situation weiter erläutern (bitte bearbeiten Sie dazu Ihre Frage). Wenn Ihr Sub-Member auf jedem Form_Open ausgeführt wird, spielt es keine Rolle, ob die Änderung dauerhaft ist. Oder funktioniert Ihre '.FormatConditions.Delete'-Zeile überhaupt nicht, nicht einmal für die aktuelle Formularinstanz? – Andre

+0

Es ist das letztere. Die Linie funktioniert überhaupt nicht. – jjjjjjjjjjj