473,508 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

report is wider than the page

4 New Member
I have a crosstab report that generates through vba code. The data columns are variable and the names of columns and their number changes every time. Very often the report size is wider than the page size, even with the landscape layout. When that happens the page numbers and total amount of pages are incorrect. The additional pages are being ignored in calculation of [Page] and [Pages]. I tried to play with page and format events of different section, but couldn't figure out how to print correct page numbers on every page. Ideally I would like to also repeat some row headers too, but the page numbers are more important. Please advise, thank you!
Nov 7 '14 #1
6 1435
twinnyfo
3,653 Recognized Expert Moderator Specialist
Davit,

This is one of the challenges when using Cross Tab queries for reports. The biggest challenge, as you described, is that the column count can change--thus also making it impossible to use as a standard record source for a report.

I'm not sure I have a solution for your problem, but you may want to consider other options for reporting, such that there are standard fields returned.

For example, lets say you have a cross tab query that returns the past 12 months' worth of data, with each month being a field. So, your columns would be "Nov-13", "Dec-13", "Jan-13"..."Oct-14". You create a report that uses each of these field names--so the control source for those text boxes would be the names of those months. This is bad news for when you move to another month. So, instead, you would want to build your query to return, instead of the actual months, fields representing the different months: "M1", "M2", "M3"..."M12". Then, you can always use the same report. You would then have some other calculated fields on that report to translate "M1" into "Nov-13". The same data is presented, but your reports are now dynamic, and can adjust to whatever dates you through at them.

This may be along the lines of how you want to begin.

Bottom line: There are probably better way to present data than through a cross tab query that just keeps expanding to the right. Although, I admit, there may be times when it is necessary.
Nov 7 '14 #2
Davit
4 New Member
Twinnyfo, thank you for your suggestion.
I considered that option, but it doesn't meet all my requirements. I was hoping to get a help for this particular situation.
One way to solve it that I have in mind is to check the report width and compare it to the paper width, but I thought there can be an easier way. Hard to believe that Microsoft haven't thought about it already.
Nov 7 '14 #3
twinnyfo
3,653 Recognized Expert Moderator Specialist
Well, keeping with your requirements, the only thing I can think of would be to change the font size for the report. This can make it difficult for others to read (depending on the size of font).

How are you getting the data into the report? Did you just embed the query into the report? I have one report that uses a cross tab query like that. As you described, I had to do it that way out of requirement.

---------------

Here is to thinking outside the box: Have you thought about exporting the query to Excel???? Then, when you print on Excel, it manages all the pagination for you......

It just might work!
Nov 7 '14 #4
Davit
4 New Member
Yes, I added the an option to see in excel, and I am just sending the query into excel. However this is only one report in the database. All others have a preview option too, so for the consistency I am keeping it.
Regarding the data entry.
I have a blank template and I am looping through the query columns and adding the boxes into the report. Then I am adding the query to the recordsourse of the report, just to make it easier to calculate the totals for groups.

When user clicks the preview button on the form, this procedure is being called and then the report is being displayed.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Select Case FrReports
  3. Case 1
  4.     sRptName = "rProd_Adj_Month_Tab"
  5.     sgRptTitle = "Adjustments by Product, Code and Month"
  6.  
  7.     DoCmd.SetWarnings False
  8.     DoCmd.Close acReport, sRptName, acSaveNo
  9.     On Error Resume Next
  10.     DoCmd.DeleteObject acReport, sRptName
  11.     On Error GoTo 0
  12.     DoCmd.CopyObject , sRptName, acReport, "rCrossTab"
  13.     DoCmd.SetWarnings True
  14.  
  15.     strFilt1 = "qCrossTab_from_WorkData"
  16.     Call OpenCrossTabReport(strFilt1, Application.CurrentProject.AllReports(sRptName), strFilter, OpenArgs)
  17.     DoCmd.Close acReport, sRptName, acSaveYes
  18.  
  19. .
  20. .
  21. .
  22. End Select
  23.  
  24.     Application.Echo True
  25.     DoCmd.OpenReport sRptName, acViewPreview, strFilt1, strFilter, acWindowNormal, OpenArgs
  26.  
  27.  
And this is the function to create the report

Expand|Select|Wrap|Line Numbers
  1. Sub OpenCrossTabReport(strSQL As String, obj As AccessObject, strFilter As String, OpenArgs)
  2.  
  3. Dim txbOne As Access.TextBox, txbSum As Access.TextBox, txbTot As Access.TextBox, lblCol As Access.Label, rpt As Report
  4. Dim db As Database, rs As Recordset, offset_pos As Long
  5.  
  6. DoCmd.OpenReport obj.Name, acViewDesign, , strFilter, acWindowNormal, OpenArgs
  7.  
  8. Set rpt = Reports(obj.Name)
  9.  
  10. rpt.lHeader1.Caption = sgCurrentMonth
  11. rpt.lHeader2.Caption = sgRptTitle
  12.  
  13. Set db = CurrentDb
  14. Set rs = db.OpenRecordset(strSQL)  
  15.  
  16. offset_pos = 0
  17. For i = 5 To rs.Fields.Count - 1
  18.  
  19. 'twip: Unit of measurement that is equal to 1/20 of a point, or 1/1,440 of an inch. There are 567 twips in a centimeter.
  20.  
  21. Set txbOne = CreateReportControl(rpt.Name, acTextBox, acGroupLevel2Header, , rs.Fields(i).Name, 4500 + offset_pos, 75)
  22. With txbOne
  23.     .BorderStyle = 0 '"Transparent"
  24.     .Format = "Standard"
  25.     .ControlSource = "=SUM([" & rs.Fields(i).Name & "])"
  26.     .SizeToFit
  27. End With
  28.  
  29. Set txbSum = CreateReportControl(rpt.Name, acTextBox, acGroupLevel1Footer, , "Sum" & rs.Fields(i).Name, 4500 + offset_pos, 0)
  30. With txbSum
  31.     .BackStyle = 0
  32.     .BorderStyle = 0 '"Transparent"
  33.     .Format = "Standard"
  34.     .ControlSource = "=SUM([" & rs.Fields(i).Name & "])"
  35.     .SizeToFit
  36.     .FontWeight = rpt.Controls("lgroupSum").FontWeight
  37.     .ForeColor = rpt.Controls("lgroupSum").ForeColor
  38. End With
  39.  
  40. Set txbTot = CreateReportControl(rpt.Name, acTextBox, acFooter, , "Sum" & rs.Fields(i).Name, 4500 + offset_pos, 10)
  41. With txbTot
  42.     .BackStyle = 0
  43.     .BorderStyle = 0  '0-Transparent
  44.     .GridlineWidthTop = 1
  45.     .GridlineStyleTop = 1
  46.     '.GridlineStyleLeft = 0
  47.     '.GridlineStyleBottom = 0
  48.     '.GridlineStyleRight = 0
  49.     .Format = "Standard"
  50.     .SizeToFit
  51.     .ControlSource = "=SUM([" & rs.Fields(i).Name & "])"
  52.     .FontWeight = rpt.Controls("lgrandTotal").FontWeight
  53.     .ForeColor = rpt.Controls("lgrandTotal").ForeColor
  54. End With
  55.  
  56. Set lblCol = CreateReportControl(rpt.Name, acLabel, acPageHeader, , rs.Fields(i).Name, 4500 + offset_pos, 10)
  57. With lblCol
  58.     .TextAlign = 3  '1-General 2-Center, 3-Right, 4-Distribute
  59.     .SizeToFit
  60.     .Width = txbOne.Width
  61.     .FontItalic = False
  62.     .FontWeight = 600 'semi-bold
  63.     .ForeColor = rpt.Controls("lprod").ForeColor
  64. End With
  65.  
  66. offset_pos = offset_pos + txbOne.Width + 100
  67.  
  68. Next i
  69.  
  70. rpt.RecordSource = strSQL
  71.  
  72. 'DoCmd.OpenReport rpt.Name, acViewPreview, , strFilter, acWindowNormal, OpenArgs
  73.  
  74. rs.Close
  75. Set rs = Nothing
  76. Set rpt = Nothing
  77. Set db = Nothing
  78.  
  79. End Sub
  80.  
Sorry for bad "handwriting" :-)

I did some macros in excel before, but this is my second access macro and the first that works with reports. I would appreciate your opinion. Thank you for your help and time.
Nov 7 '14 #5
twinnyfo
3,653 Recognized Expert Moderator Specialist
Davit,

Sorry for taking a while to get back to you on this. Your code actually looks quite nifty!

BUT!!!!

I just thought of something else.....

Since you are building your report and keeping track of where on the report your controls go.... Keep track of how many pages "wide" your report will be (perhaps use a variable called intPages, which will start at 1). Each time you reach the right margin of your page and have to add another control, increment intPages by 1. Then, in your page footer, if you have a text box to calculate pages, use the following:

Expand|Select|Wrap|Line Numbers
  1. Me.txtPages.ControlSolurce = "Page " & [Page] & " of " & [Pages] * intPages
Be sure to make this an unbound control, first.

Hope this hepps!
Nov 12 '14 #6
Davit
4 New Member
Thank you very much, twinnyfo. Your words are really encouraging, as I don't feel in Access as comfortable as I feel in Excel :-)
Nov 12 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1414
by: Craig Smesny | last post by:
How can I get the the 1st group header to print at the top of each page on my report. More or less I want to use it as the page header but it contains data from SQL. The page header section does...
2
3999
by: tom | last post by:
Hi All, Using VBA, I would like to be able to examine a report in design mode and determine its page orientation (landscape or portrait). I do not want to change the orientation. I'm fine...
0
1557
by: jovobas | last post by:
I have made a database for a quiz. Mainly questions belonging to different rounds, editions of the quiz, answers, etc. I've made a report with answeringsheets for contenders, all grouped by...
0
1389
by: Ralf | last post by:
My customer would like for the page to display with a wider data area. As it is, it only shows the data running about 3/4 the way across the browser. He would like it to reach further across b/c...
7
21708
by: steve | last post by:
Hi All I have created rdlc files and when I load them into Report Viewer at run time they appear OK If I click on 'Print layout' button on Report Viewer the view again appears acceptable ...
2
1974
by: Paulson | last post by:
Hi guys , I got a problem. I have made a pdf report using .rdlc in .net 2007. The problem is that the report has 2 parts First it displays the...
3
4676
by: | last post by:
In my report I have a calculated field that counts the number of records of the underlying table, =Count(). This field is placed in the report's header. I'd like to repeat this value on every page...
3
1877
by: cmbirk | last post by:
Hi Everyone, I am creating a report with a subreport embedded in it. I am actually creating a few of these reports for my division. I was wondering if there was some way to make sure that the...
0
1170
by: Catherine Dooley | last post by:
I'm trying to get an Access report to print the number of pages of the group instead of the number of the whole report. The code I'm using is below. The Debug statement in the middle shows that the...
3
3944
by: bdmir | last post by:
Hi All, I want to place a promotion message into a report's page if that page has a free/blank space. Maybe it would be better to track last control's coordinates on page when page is...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.