Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with BackColor

    I am using the following code in the Detail section for the "On Print" event of a report. I would like to be able to print the backcolor of a field in different colors dependent on the field value. It's not working....what am I doing wrong?

    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

    Dim lngWhite As Long
    Dim lngYellow As Long
    Dim lngPink As Long
    Dim lngRed As Long
    Dim lngGreen As Long
    Dim lngBlue As Long
    Dim lngLtGreen As Long

    lngWhite = RGB(255, 255, 255)
    lngYellow = RGB(255, 255, 128)
    lngPink = RGB(255, 164, 209)
    lngRed = RGB(255, 0, 0)
    lngGreen = RGB(0, 128, 64)
    lngLtGreen = RGB(179, 255, 217)
    lngBlue = RGB(0, 128, 192)

    If Me.DocStatus = Draft Then
    Me.DocStatus.BackColor = lngYellow
    ElseIf Me.DocStatus = "Out For Review" Then
    Me.DocStatus.BackColor = lngPink
    ElseIf Me.DocStatus = Obsolete Then
    Me.DocStatus.BackColor = lngRed
    ElseIf Me.DocStatus = Issued Then
    Me.DocStatus.BackColor = lngGreen
    ElseIf Me.DocStatus = "In For Format" Then
    Me.DocStatus.BackColor = lngLtGreen
    ElseIf Me.DocStatus = "Issued w/ALAC Approval" Then
    Me.DocStatus.BackColor = lngBlue
    End If

    End Sub

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    One thing I notice is that you have quotes around some values in your if...then statements but not around others. is the value in docstatus text?

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Help with BackColor

    Hi,
    In addition to Paul's point about quotes, you also have to have the BackStyle of the control set to normal (value of 1)rather than transparent (value of 0)
    For example,
    Me!DocStatus.BackStyle = 1
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    Star Lounger
    Join Date
    Feb 2001
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    Yes, the values in DocStatus are text.

  5. #5
    Star Lounger
    Join Date
    Feb 2001
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    Tried this as well....still doesn't work. Any other suggestions?

  6. #6
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    When you say "it doesn't work" what results are you getting exactly?

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Edmonton, Alberta, Canada
    Posts
    326
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    Haven't played with colours in reports and where to set them is not mentioned in the documentation, but since other formatting (e.g. setting visible/invisible) is supposed to be done in the format event code rather than the print event code, I'd try putting your code there.

    Also, I suspect you are missing a bunch of double-quotes, unless draft, obsolete, etc. are variables.

  8. #8
    Star Lounger
    Join Date
    Feb 2001
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    BackColor appears as either white or transparent.

  9. #9
    Star Lounger
    Join Date
    Feb 2001
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    Fixed the quote issue and also tried the On Format event without success. Thanks!

  10. #10
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Help with BackColor

    Hi,
    It might be worth trying this variation on your code:
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

    Dim lngWhite As Long
    Dim lngYellow As Long
    Dim lngPink As Long
    Dim lngRed As Long
    Dim lngGreen As Long
    Dim lngBlue As Long
    Dim lngLtGreen As Long
    Dim lngColour as Long

    lngWhite = RGB(255, 255, 255)
    lngYellow = RGB(255, 255, 128)
    lngPink = RGB(255, 164, 209)
    lngRed = RGB(255, 0, 0)
    lngGreen = RGB(0, 128, 64)
    lngLtGreen = RGB(179, 255, 217)
    lngBlue = RGB(0, 128, 192)

    Select Case Me!DocStatus
    Case "Draft"
    lngColour = lngYellow
    Case "Out For Review"
    lngColour = lngPink
    Case "Obsolete"
    lngColour = lngRed
    Case "Issued"
    lngColour = lngGreen
    Case "In For Format"
    lngColour = lngLtGreen
    Case "Issued w/ALAC Approval"
    lngColour = lngBlue
    Case Else
    lngColour = lngWhite
    End Select
    With Me!DocStatus
    .BackStyle = 1
    .BackColor = lngColour
    End With

    End Sub
    Hope that works.
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    Only other thing I can think of is what Rory suggested - the back style....my experiments with your code are working.

  12. #12
    Star Lounger
    Join Date
    Feb 2001
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    Unfortunately this doesn't work either. I am able to have the entire background of the Detail section change color based on the DocStatus value, however, cannot quite figure out how to change the DocStatus field's backcolor property...this has been very frustrating.

  13. #13
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Help with BackColor

    Is the database small enough to post here? If not, would you like to email me a copy at rarchi5404@aol.com and I'll take a look at it, since I'm running out of ideas here! I'll post any answers here if I find them.
    Regards,
    Rory

    Microsoft MVP - Excel

  14. #14
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    What is the name of the control on your report? If it is the same as the underlying field then try changing the name of the control to some thing different and then change your code accordingly.

  15. #15
    Star Lounger
    Join Date
    Feb 2001
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with BackColor

    Problem solved....thanks for everyone's help. As it turns out my code was correct however, for some reason the problem was related to the SQL statement referenced as the data source....doesn't make sense I know but I am referencing the table now as the datasource and it works great!

Page 1 of 2 12 LastLast

Posting Permissions

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