Results 1 to 8 of 8
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Visible/not on report (XP)

    On a report, I have a field that can display one of three choices from a lookup table. The report pulls its data from query. The detail section displays a list of courses, and the field in question denotes whether a course is Core, Required, or Optional. If the course is Core, I want the data in the Course Title field to display as <font color=red>Bold Red</font color=red>. Otherwise, the data should display normally.

    I just need a little help with the code. Also, I've already got one bit of code in the OnFormat property of the Detail section

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Visible/not on report (XP)

    You should be able to do this with Conditional Formatting.
    - Open the report in design view.
    - Select the Course Title text box.
    - Select Format | Conditional Formatting...
    - Under Condition 1, select Expression Is from the dropdown list.
    - In the text box next to it, enter something like [FieldName] = "Core" where FieldName is the name of the field with the three choices. I have assumed that this field contains the names Core/Required/Optional; if it contains a numeric code, use that instead of "Core".
    - Use the buttons to the right of the text box to set the formatting you want.
    - Click OK.

    If you want to use the On Format event, insert code like this in the event procedure, either before or after the code that takes care of the alternate shading:

    If [FieldName] = "Core" Then
    Me.[Course Title].Bold = True
    Me.[Course Title].ForeColor = vbRed
    Else
    Me.[Course Title].Bold = False
    Me.[Course Title].ForeColor = vbBlack
    End If

    Replace Course Title by the actual name of the control.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Visible/not on report (XP)

    Thanks, Hans

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Visible/not on report (XP)

    Oops, that's what you get for writing air code. It should have been FontBold instead of Bold. Sorry about that.

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Visible/not on report (XP)

    "...air code"? <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Visible/not on report (XP)

    Air Code is written on the fly, usually in a text editor, without testing or compiling. It's sort of the programmer's equivalent of air guitar. You make all the right moves and hope that they work in the real world. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Visible/not on report (XP)

    Kindly disregard, Hans! I finally figured it out for myself! Thanks a million!

    Hello, Hans: Let me add another wrinkle to this topic. Now I have, not two, but three priorities to contend with: Core, Required, and Optional. I tried grouping the courses on the report, but the boss wants one continuous list in alphabetical order. So I'd like to use the VBA approach. (I don't think I can get what I need with Conditional Formatting, n'est pas?) By the way, I got the code from your earlier reply to work correctly once I changed "Bold" to "FontBold," as you corrected it.)

    The only problem I have is with putting the second condition into the statement. I tried to wing it, but something ain't right. What I want to get is something like this:

    If [Priority] = "Core" Then [Course] = Bold Red
    If [Priority] = "Optional" Then [Course] = Blue (regular, not bold)
    Otherwise, [Course] displays normally (no color, regular)

    Thanks!!

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Visible/not on report (XP)

    You can specify up to three conditions in conditional formatting, so it should be possible to use it here too. The Conditional Formatting dialog has an Add>> button to specify additional conditions and formatting.

    In VBA, you can use the Select Case statement instead of If ... Then:

    Select Case Me.[Priority]
    Case "Core"
    Me.[Course].FontBold = True
    Me.[Course.ForeColor = vbRed
    Case "Optional"
    Me.[Course].FontBold = False
    Me.[Course].ForeColor = vbBlue
    Case Else
    Me.[Course].FontBold = False
    Me.[Course].ForeColor = vbBlack
    End Select

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •