Results 1 to 3 of 3
  1. #1
    skyatis is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    11

    Conditional formatting *almost* working

    Hello

    I wrote a few lines of code to apply conditional formatting to a combo box when its form is loaded. It doesn't quite work.



    However if I then go to Layout view - Format - Conditional Formatting I can see the rules there. When I click on 'Apply' the form repaints with the conditional formatting applied.

    What am I missing in the procedure?

    The combo box is 'cmbAction'

    Code:
    Private Sub Form_Load()
    
    Dim fc As FormatCondition
    
    Me.cmbAction.FormatConditions.Delete
    
    Set fc = Me.cmbAction.FormatConditions.Add(acExpression, acEqual, "[cmbAction] = Landing")
    Set fc = Me.cmbAction.FormatConditions.Add(acExpression, acEqual, "[cmbAction] = Exercise")
    
    Me.cmbAction.FormatConditions(0).BackColor = 100000
    Me.cmbAction.FormatConditions(1).BackColor = 50000
    
    Me.cmbAction.FormatConditions(0).Enabled = True
    Me.cmbAction.FormatConditions(1).Enabled = True
    
    Me.Repaint
    
    End Sub

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Try putting single quotes around those text options:
    Set fc = Me.cmbAction.FormatConditions.Add(acExpression, acEqual, "[cmbAction] = 'Landing'")
    Set fc = Me.cmbAction.FormatConditions.Add(acExpression, acEqual, "[cmbAction] = 'Exercise'")

  3. #3
    skyatis is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    11
    As simple as that! Thank you Bulzie!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 11-25-2016, 07:26 PM
  2. Replies: 2
    Last Post: 10-15-2015, 11:46 AM
  3. Conditional Formatting Not Working Properly
    By davidmcleod in forum Access
    Replies: 14
    Last Post: 06-25-2015, 11:04 AM
  4. Replies: 7
    Last Post: 03-28-2014, 05:44 PM
  5. Conditional Formatting not working properly
    By GraeagleBill in forum Reports
    Replies: 3
    Last Post: 03-08-2014, 07:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums