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

    Conditional report format in vba

    I'm trying to create a report where each line has conditional formatting dependant on the contents of a field.



    The standard Access conditional formatting system works OK but I want more control; borders, row height etc.

    I can't seem to get this working in vba. Here's the code I used for a table with fields named 'Species' and 'AnimalType':

    Code:
    Private Sub Report_Load()
    If Me.AnimalType = "Fish" Then
        Me.Species.BorderWidth = 5
        Me.Species.BorderColor = RGB(0, 255, 255)
    ElseIf Me.AnimalType = "Mammal" Then
        Me.Species.BorderWidth = 2
        Me.Species.BackStyle = 0
        Me.Species.FontSize = 12
        Me.Species.ForeColor = RGB(255, 0, 0)
    End If
    End Sub
    Every line is formatted as a Mammal. How can I get each line formatted differently according to the AnimalType field?

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The event is incorrect, try doing that code on the Detail OnFormat.

  3. #3
    skyatis is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    11
    I tried that but the code doesn't execute at all in Detail_Format.

    So I tried putting the same code in all the Detail events. It executes in Detail_Paint, but produces the same result; all lines in the report are formatted the same way.

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    It should work in the OnFormat Event on the Detail section of the report. Make sure you have it in the right place. I did a test and it worked. Make sure your fields are in that Detail section. Also when you run the report, select the Print Preview, not the Report View selection.

  5. #5
    skyatis is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    11
    Ah. Thank you. It works fine; I just hadn't understood the difference between Report View and Print Preview.

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

Similar Threads

  1. Conditional Format question
    By JimO in forum Access
    Replies: 3
    Last Post: 06-10-2016, 05:13 PM
  2. combobox + conditional format
    By markjkubicki in forum Forms
    Replies: 4
    Last Post: 06-24-2014, 04:25 PM
  3. Conditional number format
    By terryvanduzee in forum Forms
    Replies: 1
    Last Post: 07-14-2011, 01:29 AM
  4. Advanced Report Conditional Format
    By MrHoliday in forum Forms
    Replies: 2
    Last Post: 08-25-2010, 11:58 PM
  5. Conditional Format Query
    By Schwagr in forum Queries
    Replies: 3
    Last Post: 03-20-2006, 02:39 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