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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report to print as "graybar" 1

Status
Not open for further replies.

LaurelLee

Programmer
Mar 2, 2004
117
US
Hello,

I am trying to format the report to print similar to a graybar report, but with the color changing only when a certain column's data changes. And to complicate things a bit, I have a subreport within the main report. So, the resulting report would look something like this:


33556622 subreportdata data from main report<grey>
subreportdata <grey>
subreportdata <grey>
3355825 subreportdata data from main report<white>
subreportdata <white>
subreportdata <white>
subreportdata <white>

etc...



I tried a procedure I found here, which changed every other line, and that worked fine when I put it within the subreport and the main report. However, my code is not doing a darn thing. I am wondering if there is a way to use the code I got from TT to do this.

Here is my code(this is abbreviated for space reasons, as there are a lot of field names)
Code:
Private m_intCounter As Integer
Private m_strPrevWPC As String

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_Detail_Format

Const GREY As Long = 13553358

    'Increment counter only if record is a different txtWP from the previous textWP.
    If m_strPrevWPC <> txtWP Then m_intCounter = m_intCounter + 1
    
        'Set greybar
        'Greybar is Grey on even counts (counts based on change of WPC)
        If m_intCounter Mod 2 = 0 Then
            txtBlock.BackColor = GREY
            txtZONE.BackColor = GREY
            txtWP.BackColor = GREY
            txtPLN_S.BackColor = GREY
            txtPLN_C.BackColor = GREY
            
        Else 'Odd counts are normal back color
            txtBlock.BackColor = vbWhite
            txtZONE.BackColor = vbWhite
            txtWP.BackColor = vbWhite
            txtPLN_S.BackColor = vbWhite
            txtPLN_C.BackColor = vbWhite
            PCT_C.BackColor = vbWhite
            
        End If
        
    
    m_strPrevWPC = txtWP
    
Err_Detail_Format:
    If Err <> 0 Then MsgBox Err.Number & ":  " & Err.Description
    
End Sub



And here is the code from TT:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    'Michael Red.   2/13/2002.      To 'Toggle the backolor, which
    'Provides alternate line shading
    Const XorToggle = 4144959

    Me.Detail.BackColor = Me.Detail.BackColor Xor XorToggle


End Sub



Any thoughts are greatly appreciated!

Laurel

___________________________________________________________
With your thoughts you create the world--Shakyamuni Buddha
 
First of all your code is still using the everyother line changing color from Grey to White. This is done with the line counters and the Mod functions. Your example states that you want the backcolor to change as txtWP values change.

Secondly your code is changing the backcolor of the textbox controls on the form. I see no problems with this assignment but it differs from what you stated that you want. You said you wanted a Greybar look to your report. Well if so then change the BackStyle property of your controls to Transparent and then change your code to modify the .backcolor of the Detail section as the TT code had previously shown.

I can modify your code for you if this is confusing. Just let me know.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
I know that the first chunk of code works, as it was used in the old version of this report (not that it is necessarily great code, but I am going for whatever will get the jonb done right now!). The old report didn't use any subreporting, which is where I see my problem being. The second chunk of code did work, but did not discriminate any values and just changed every other line. I understood the first code to only increment the counter based on the first if statement, If m_strPrevWPC <> txtWP Then m_intCounter = m_intCounter + 1. So, in essence, it is seeing every piece of the report with the same txtWp as one line. This is, of course, not accounting for the subreport.

Secondly your code is changing the backcolor of the textbox controls on the form. I see no problems with this assignment but it differs from what you stated that you want. You said you wanted a Greybar look to your report.

My report is a whole bunch of text boxes strung together within the detail section. I guess I don't understand what the difference is that you are talking about. ?? The textboxes are referring to controls on the report.

Could you please elaborate? Thanks for your help, again!

Laurel


___________________________________________________________
With your thoughts you create the world--Shakyamuni Buddha
 
I was just trying to point out that if you set your controls backstyle property to transparent so that you see through them to the Detail Section backcolor then all you need to do is change the Detail Section backcolor from white to grey whenever appropriate. The white or grey color will then show through all the controls except the actual black values which is the forecolor.

If you set the properties of your controls to transparent then the following code would be all that is necessary to change the mainforms rows color:

Detail section FORMAT event code:
Code:
Const GREY As Long = 13553358
    'Increment counter only if record is a different txtWP from the previous textWP.
    If m_strPrevWPC <> txtWP Then m_intCounter = m_intCounter + 1
        If m_strPrevWPC <> txtWP Then m_intCounter = m_intCounter + 1
        'Set greybar
        'Greybar is Grey on even counts (counts based on change of WPC)
        If m_intCounter Mod 2 = 0 Then
            Me.Detail.BackColor = GREY           
        Else 'Odd counts are normal back color
            Me.Detail.BackColor = vbWhite             
        End If
    m_strPrevWPC = txtWP

Now as far as the subreport you should be able to make a reference back to the Main forms Detail section property .backcolor and assign it to the .backcolor property of each detail section row of the subreport. Was that a circular reference there? Give that a try and see if that works.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Oh, I see. I do already have them set to transparent, so I guess that I was adding an unnecessary step there. I thought that was an awful lot of code just to be changing the color! It is all of these little things that I am unaware of!! I will give that a whirl and see what happens. I will post back later. Thanks!

___________________________________________________________
With your thoughts you create the world--Shakyamuni Buddha
 
Okay, I am having success with the main report, but the subreport is a little confusing. In terms of pseudocode, it would go something like this:

if childfield=masterfield
then childfield background color = masterfield background color

I am unsure how to code this. How do you reference the main report within the code for the subreport?



___________________________________________________________
With your thoughts you create the world--Shakyamuni Buddha
 
In the On Format event procedure of the Detail section of the subreport you can use this as an example of how to make the color assignment:

Code:
Me.Detail.BackColor = [Forms]![[red]mainreportname[/red]].Detail.BackColor

Remember that you must set all of your subreport controls backstyle property to Transparent also for this to work.

I think this is all that is necessary as you have already determined the appropriate color in the Main forms Detail Section Format procedure. So, we just need to steal it and use it in the subform. Yes???

Let me know how this works.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
That worked perfectly. Too bad I don't have my own Bob Scriver here right next to me to teach me all these things everyday! I would be a LOT more productive. I seem to have a tendency to make things a lot harder than they need to be. Simplicity is key!!

Thanks again, Bob!


Regards,
Laurel

___________________________________________________________
With your thoughts you create the world--Shakyamuni Buddha
 
LauraLee, thanks for the Star and the kind words. Do not feel alone as I have been right where you have been before. Just time and experience solves many of these issues. Plus, I will say that I taught myself ACCESS with the help of forums like this. I have settled into TT because I feel that it is the best format.

Before I retired I had two systems setup in my office. One to work on projects and one that monitored TT. I kept track of the threads and when something looked interesting or I had no idea what they were talking about I clicked the link to Mark it for email notification. Then just watch the code come rolling in.

And, remember you do have Bob Scriver sitting right next to you. Maybe a long way off but if I see you posting I will try to respond.

Good luck.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
I heartily agree with you that TT has the best format, and it seems also to have the most informed people replying. I am grateful every day to have stumbled across it!

Thanks again!

___________________________________________________________
With your thoughts you create the world--Shakyamuni Buddha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top