Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight Group 2

Status
Not open for further replies.

lars7

Technical User
Aug 16, 2005
817
GB
Hi,
Is it possible highlight a certain group whenever they appear in a Report. I would like to highlight a staff grouping from the others so that they could be easily picked out.
 
You can set properties (colors, fonts, etc) of sections and controls. Some of this can be handled with Conditional Formatting and other settings require code. The code would normally reside in the On Format event of the report section containing the controls.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hi There,
I have tried following code but I get an error message can anyone see why.

Option Compare Database


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

Const WHITE = 16777215
Const YELLOW = 65535

If (Me![GRP_CODE] = "8J") Then
Me![FORENAME].BackColor = YELLOW
Me![SURNAME].BackColor = YELLOW
Me![JD CODE NO].BackColor = YELLOW
Me![JOBDESCRIPTION].BackColor = YELLOW
Else
Me![FORENAME].BackColor = WHITE
Me![SURNAME].BackColor = WHITE
Me![JD CODE NO].BackColor = WHITE
Me![JOBDESCRIPTION].BackColor = WHITE
End If

End Sub
 
We are having a little trouble seeing your error message ;-)

Have you tried this with the code in the On Format event rather than the On Print event?

Also, you can use the built-in constants of vbWhite and vbYellow rather than creating your own.

If the controls are all adjacent, you might want to place a rectangle behind the controls and change the color of the rectangle. Make sure the other controls are set to transparent.


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hi again,
I'm quite new to this and I can't find the on format.I found this code on a example I downloaded, it was for shading every second row on a report and then I modified it slightly to fit into my report. I'm not sure what you mean by built in constants could you explain that for me in a little more detail.

Thanks.
 
What dookom is saying is like this

Code:
 Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Select Case Me![GRP_CODE].Value
    Case Is = "8J"
        Me![FORENAME].BackColor = vbYellow
        Me![SURNAME].BackColor = vbYellow
        Me![JD CODE NO].BackColor = vbYellow
        Me![JOBDESCRIPTION].BackColor = vbYellow

    Case Else
        Me![FORENAME].BackColor = vbWhite
        Me![SURNAME].BackColor = vbWhite
        Me![JD CODE NO].BackColor = vbWhite
        Me![JOBDESCRIPTION].BackColor = vbWhite
    End Select
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
Hi,
I did like you said but it stoped again at the same place as the other one(on the last line),

Case Else
Me![FORENAME].BackColor = vbWhite
Me![SURNAME].BackColor = vbWhite
Me![JD CODE NO].BackColor = vbWhite
Me![JOBDESCRIPTION].BackColor = vbWhite

The error message reads,

Object doesn't support this property or method.
 
What type of control is that? TextBox? ComboBox? else..?

________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
Ok comment out the line that raises error. then try if the error goes to top line try commenting that too.
Code:
Case Else
        Me![FORENAME].BackColor = vbWhite
        Me![SURNAME].BackColor = vbWhite
        Me![JD CODE NO].BackColor = vbWhite
 [COLOR=green]       'Me![JOBDESCRIPTION].BackColor = vbWhite[/color]


________________________________________________________
Zameer Abdulla
Help to find Missing people
Do not cut down the tree that gives you shade.
 
I think there was a problem with that field, for some reason it stoped on that same line in the top half of the code.
I have changed the code,I had to add another field,"Payno" and I changed the job description field to short_grade,


Option Compare Database

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Select Case Me![GRP_CODE].Value
Case Is = "8J"
Me![PAYNO].BackColor = vbYellow
Me![FORENAME].BackColor = vbYellow
Me![SURNAME].BackColor = vbYellow
Me![JD CODE NO].BackColor = vbYellow
Me![SHORT_GRADE].BackColor = vbYellow

Case Else
Me![PAYNO].BackColor = vbWhite
Me![FORENAME].BackColor = vbWhite
Me![SURNAME].BackColor = vbWhite
Me![JD CODE NO].BackColor = vbWhite
Me![SHORT_GRADE].BackColor = vbWhite
End Select
End Sub

The report opens now but there is no difference is the colours.
 
I don't use " Is= " in the Case...
Is there a control in the detail section named "GRP_CODE" and are there one or more records with the value "8J"?
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Select Case Me![GRP_CODE].Value
    Case "8J"
        Me![PAYNO].BackColor = vbYellow
        Me![FORENAME].BackColor = vbYellow
        Me![SURNAME].BackColor = vbYellow
        Me![JD CODE NO].BackColor = vbYellow
        Me![SHORT_GRADE].BackColor = vbYellow

    Case Else
        Me![PAYNO].BackColor = vbWhite
        Me![FORENAME].BackColor = vbWhite
        Me![SURNAME].BackColor = vbWhite
        Me![JD CODE NO].BackColor = vbWhite
        Me![SHORT_GRADE].BackColor = vbWhite
    End Select
End Sub

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I removed the " Is= " from the code and then I found another problem.

I hadn't changed the setting of the backstyle from transparent to normal.
It's looking good now thanks to both of you for your time and patience. Here is the code for anyone who needs it.

Option Compare Database

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Select Case Me![GRP_CODE].Value
Case "8J"
Me![PAYNO].BackColor = vbYellow
Me![FORENAME].BackColor = vbYellow
Me![SURNAME].BackColor = vbYellow
Me![JD CODE NO].BackColor = vbYellow
Me![SHORT_GRADE].BackColor = vbYellow

Case Else
Me![PAYNO].BackColor = vbWhite
Me![FORENAME].BackColor = vbWhite
Me![SURNAME].BackColor = vbWhite
Me![JD CODE NO].BackColor = vbWhite
Me![SHORT_GRADE].BackColor = vbWhite
End Select
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top