Solved

Display in header the last record on a page

Posted on 2009-05-14
19
1,210 Views
Last Modified: 2012-05-07
I've been trying to find an answer to my question with no luck.

Here is what I'm trying to accomplish.

I have a directory and on each page I want to display on the header which is the first last name on that specific page and also which is the last last name on the page.

Remember it has to be in the header, not the footer, and it has to have the first "last name" displayed on the page and the last "last name" displayed on the same page.

Thank you for your help!
0
Comment
Question by:diazluna
  • 7
  • 6
  • 5
  • +1
19 Comments
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
I don't believe you can do this in the page header.
Use a group header instead and re-organise your headings.

You need to create a group which splits the records based on how many you can fit on a page.
For example if you want 50 records on a page you would create a formula field..

whilereadingrecords;
numbervar x;
x:=x+1;
x\50

and then group on this formula field.

You can then use Insert Summary to add the minimum and maximum values for the LastName field into the group header and use the section expert to force a new page after each group footer.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
We dealt with this question before.  I don't recall that we ever came to a good solution.

Nice idea on the formula but I read recently that the variables dont maintain the value except in the printing pass.

I can't find the question  on this.

I think one of the suggestions was to add a subreport to the group header.  Its purpose was given the starting record 9name) to find the 50th or 60th whatever fits on a page and display that last name.

mlmcc
0
 
LVL 2

Author Comment

by:diazluna
Comment Utility
The number of records on a page is uncertain because I'm using 4 columns with variable fields that may or may not be blank and are suppressed.

Any other ideas on how to accomplish this?  This is absolutely a must for the directory that I'm trying to build.

I hope someone has an idea of how I can accomplish this.

Thank you!
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
The only other way would be to have the subreport essentially reproduce the page but not display it and capture the name from it.

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
But if the number of records on the page is variable, I don't think the subreport idea will work either.  The subreport would really have to reproduce the page, which may or may not be possible to begin with, but even if it was, you have to suppress everything but the last last name in the subreport, which means that it can't reproduce the page.  Correct?  I mean, with everything suppressed, there would be no page breaks or anything else.  If the subreport can't just read X number of records and say "this would be the last record on the page", I don't see how it could work.

 If you can't come up with some way to know how many records would be on a page, I don't see any way to do this.

 James
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Probaly accurate.

The only way it might work is if the subreport was shrunk to be very short and not allowed to grow.

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
Yeah, I guess that could work, so the subreport is going through the motions of producing the page, but the main report doesn't allow it to show.  Good idea.

 James
0
 
LVL 2

Author Comment

by:diazluna
Comment Utility
Thank you both - Could you please describe the steps I need to take to make this work?  At this point it seems unclear to me as to what I need and don't need to do.

Thanks again!
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
The first question is, can you create a subreport that reproduces the page layout of the main report?  Subreports have some limits that may make that difficult.  You can start by telling CR to import the current report as a subreport and go from there.

 It might simplify things if you could attach your report to a message, so that we could take a look at it.  It would be even better if you could save some data with the report and post that, so that we could see the output, as long as there is nothing "confidential" in the data.  If you're going to post a report, EE only accepts certain file extensions and RPT is not one of them, so change the extension to one of the recognized types (eg. TXT) and u/l that, and add a note to the file saying that the extension needs to be changed back to RPT.

 James
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Author Comment

by:diazluna
Comment Utility
I'll try recreating the main report and make it a subreport, but once that's ready what do I do with the subreport?  I think I'll have to insert it into the main report, and then what?  Include it in the header, detail? Should I use variables to get the first or the last last name? Do I need to create formulas?  Suppress the subreport?

Thank you for your assistance.
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
The idea is to create a subreport that reproduces the page layout of the main report, so that the subreport will fit the same number of records on a page.


 You would put the subreport somewhere in a page header section of the main report.  This would probably need to be a section above your current page header section.


 [ Don't worry too much about the starting and ending parameter stuff below until you've read the entire message, because, as noted later, that may not be necessary after all ]

 If possible, you would include a parameter(s) in the subreport that you could use to tell it which record to start with.  In theory, you would link a field(s) in the main report to the parameter(s) in the subreport, so the subreport would get the values from the first record on the current page of the main report and start with that record.  Otherwise, the subreport would be running for all records at the start of every page in the main report and you'd have to try to pass it a page number or something, so that the subreport knew which value to pass back to the main report.

 It would be nice if you could also pass the subreport something to tell it how many records to read, so that it could read enough records to reproduce the current page on the main report, get the last name on that page, and quit.  But that may not be possible, in which case the subreport will read all of the records, starting (hopefully) with the first one on the current page in the main report.  In that case the subreport will need to specifically save the last name from the first page it creates and not the pages after that, but if you can get it to recognize the last name on a page, then it would hopefully simply be a matter of saving the last name on the first page and then on the remaining pages, seeing that a name has already been saved and leaving it alone.

 If your main report is reading a lot of records, then the above may be a deal killer, because the subreport may end up reading all of those records for every new page.  It depends on whether or not you can pass the subreport some kind of starting and ending parameters to limit what it has to read for each page.
 At best, if you can pass starting and ending parameters to the subreport, it will be reading all of the same records a second time, one page full at a time.
 Middle ground would be if you could pass a starting parameter to the subreport, but not an ending one.  Then it would be reading all of the records from the current page on for each new page on the main report (eg. if there were 10 records per page, the subreport would read from record 1 to the end for the first page, from record 11 to the end for the second page, and so on).
 At worst, the subreport will be reading all of the same records for every page (if the main report has 10 pages, the subreport will read all of the records 10 times).


 You would use a shared variable to save the last name on the page in the subreport and pass that back to the main report.  This is why the subreport would probably need to be in a page header section above your current page header.  You have to be sure that the subreport is executed before you try to use the variable in the main report, and the only way to do that is to put the subreport in an earlier section of the main report.  If you want to display the last name on the page in the page header of the main report, the subreport should be in a page header section above that.


 You would not suppress the subreport, because if you suppress a subreport, it is not executed at all.  In other circumstances you could set the subreport up so that it produces no output (and just sets variables for the main report to use), but in this case the subreport _has_ to produce output, because it has to duplicate the page layout of your main report, in order to determine what will be the last record on the page.  So you have to let the subreport go through the motions of producing output and not suppress it, but you can make the subreport field on the main report very short and uncheck the "can grow" box, so you won't actually see all that output on the main report.


 As you can see, this is not a trivial matter.  And I can't really guarantee that it will work (in fact, I have serious doubts that you'll be able to get the paging right).


 FWIW, I just thought of another variation on this that, while a little more complicated in some ways, might be much simpler to implement in the end.

 Rather than try to run the subreport for each page, you could run the subreport once for the entire report and have it save the last name on each page in an array.  Using an array is the "more complicated" part, but aside from that it would probably be much simpler.  The subreport would still have to reproduce the page layout of the main report and be able to identify the last name on each page, but the subreport would be put in the report header of the main report (not the page header) and only be executed once.  It would save the last name on each page in an array, indexed by the page number, and then the main report would get the last names from that array.

 I did literally just think of this as I was writing this message, so there may be some issues that I don't see, but at this point, I think that that would probably be the way to go.  Arrays in CR are limited to 1000 elements, so if you're going to have more than 1000 pages on a report, that's something that you'd have to deal with, but even then, this would probably be the better approach.


 The key remains, can you reproduce the page layout in the subreport and identify the last name on a page of the subreport?  If you can do that, then I think this can work.  To be honest, I have my doubts about the getting the page breaks where you need them (without which you presumably won't be able to identify the last name on a page), but I could be wrong.


 For testing purposes, you might want/need to allow the subreport to show (check the "can grow" option), so that you can see what it's doing.  You might also want to temporarily add a manual record selection to the subreport, so that it's only reading a little more than a page worth's of records, just to make the testing easier/faster.  If the subreport is reading just over one page of records and you can identify the last name on the first page, that would be a good start.

 James
0
 
LVL 2

Author Comment

by:diazluna
Comment Utility
I like the array approach but I won't be implementing it on this project anymore because of its complexity. I was able to pull the first last name and the last last name on the footer, so I guess that's a good starting point for my subreport.

I want to thank you because you've spent a lot of time coming up with a solution.  I'd like to award you the points, however, it won't be accurate to say that this issue has been solved without a formula for the subreport to gather the first and last last names and for the main report to create the array and also to display the value on each page.

If you can post those formulas I'll then accept it as solution.  I hope this could help someone in the future.

Thanks again!
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
The formulas would be the same way you are getting them in the subreport.  It would simply set a shared variable in the subreport page footer

mlmcc
0
 
LVL 34

Accepted Solution

by:
James0628 earned 50 total points
Comment Utility
If you have a subreport that outputs the first and last name on a page, then at the point where you output each of those, you would have a formula that put that name in a variable.  Something like the following:

For the first name on the page:

Shared StringVar first_name;
first_name := {table.name}


 For the last name on the page:

Shared StringVar last_name;
last_name := {table.name}


 If you were using an array to save the last name on each page, then, in theory, you could use something like the following to save the names:

Shared StringVar Array last_names;
last_names [ PageNumber ] := {table.name}


 However, I suspect that PageNumber won't give you what you want in the subreport.  If not, then you could hopefully just replace that with a numeric variable that you simply increment each time the formula is evaluated, to put the name in the next slot.  Something like:

Shared StringVar Array last_names;
Global NumberVar i;
i := i + 1;
last_names [ i ] := {table.name}


 Then you'd use something like the following in the main report to output the name for each page:

Shared StringVar Array last_names;
last_names [ PageNumber ]



 That's just the basic idea.  There are various other details that would need to be handled, like other formulas that declare or reset the variables.  The specifics would depend on your report and subreport and how you wanted to handle certain things.
 For example, you'd have to decide how big you wanted to make the array to start with and use Redim to size it (eg. Redim last_names [ 100 ] to give it 100 elements) when it was first declared.  And if there was a chance that you might need more elements (using the above example, if the report might run over 100 pages), then you'd need to include something in the formula to check for that and expand the array, if necessary, using Redim Preserve (a plain Redim will erase the current contents of the array, but Redim Preserve will keep them).


 FWIW, I see that you assigned all of the points to mlmcc.  Since you were talking to me, I'm guessing that that was a mistake, although I do think he deserves partial credit (it was his suggestion to have the subreport reproduce the page layout of the main report, but make the subreport small so that its output isn't actually visible on the main report).

 James
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Question reopened for a more appropriate award of points.

mlmcc
Zone Advisor
0
 
LVL 2

Author Closing Comment

by:diazluna
Comment Utility
I just said that the solution is partially accurate because I have yet to try it.

Thanks again!
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
Sorry.  I don't mean to nitpick, but I really think mlmcc deserves some of the credit here.  You can accept more than one post by more than one person as the solution and split the points between them.

 As for the rest, if you need some additional help with the formulas, etc., you can always come back.  With more details about your report and subreport, we can provide more detailed answers (exactly what to put in the different formulas, etc.).  Since you've accepted a solution to this question, if you do come back, it might be best to start a new question, even though it would really be a continuation of this one.  I don't know what the EE policy would be for that situation.  If nothing else, posting a new question would get the attention of more people.  The only people that would see a new post in this old question would be those of us that were involved in it.  If you wanted to make sure that we saw the new question, you could post a link here pointing to the new question.

 James
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Or you could use the ASK A RELATED QUESTION link just below the last comment.  In that way a new question is asked but all partici[ants in this question also get notified.

As far as a split of points go it is only a 50 point question so not much to worry about there.

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
You know, I hadn't thought to check how many points there were.  :-)  I guess you're right.

 James
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now