473,383 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Force paging in report based on crosstab query with dynamic number of columns

PLEASE HELP - I NEED THIS TO COMPLETE A CONTRACT!!!
Hi all,
I have a report based on a crosstab query. The number of columns is dynamic based on the selection criteria the user chooses. I’ve set up my report to hold 11 columns on a page. The first column is a student name and the rest are statuses of various activities for the student. I want the report to page after the first 11 columns, but repeat the student name on each page. Currently the report just shows the last pages worth of data. It appears that it is going through the code rewriting each page as the first page. How do I force it to page at the proper time?

I open the report from a form where the user selects the program to be reported on. I’ve been banging my head against this for awhile and appreciate any help you can give.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. Dim conNumColumns As Integer
  3. Dim qdf As DAO.QueryDef
  4. Dim rst As DAO.Recordset
  5. Dim intColumnCount As Integer
  6. Dim pageColumnAdd As Integer
  7. Dim pageNumColumns As Integer
  8. Dim intX As Integer
  9.  
  10. ' Don't open report if frmEmployeeSales is not loaded.
  11. If Not IsLoaded("frmStudentParticipation") Then
  12. Cancel = True
  13. MsgBox "Please open this report from frmStudentParticipation.", vbExclamation
  14. Exit Sub
  15. End If
  16.  
  17. On Error GoTo Handle_Err
  18.  
  19. ' Set record source.
  20. RecordSource = "qryStudentParticipation"
  21. ' Open QueryDef object.
  22. Set qdf = CurrentDb.QueryDefs("qryStudentParticipation")
  23. ' Set query parameters based on values in form.
  24. qdf.Parameters("Forms![FrmStudentParticipation]!cmbProgramID") = Forms![FrmStudentParticipation]!cmbProgramID
  25.  
  26. ' Open recordset.
  27. Set rst = qdf.OpenRecordset
  28. ' Don't open report if there are no data.
  29. If rst.RecordCount = 0 Then
  30. MsgBox "No records found.", vbInformation
  31. Cancel = True
  32. GoTo Handle_Exit
  33. End If
  34.  
  35. ' Fix number of columns in crosstab query.
  36. conNumColumns = 11
  37. pageNumColumns = 11
  38. intColumnCount = rst.Fields.Count - 1
  39. pageColumnAdd = 0
  40.  
  41. If intColumnCount - pageColumnAdd >= conNumColumns Then
  42. pageNumColumns = conNumColumns
  43. Else
  44. pageNumColumns = intColumnCount - pageColumnAdd
  45. End If
  46.  
  47. Do While pageNumColumns > 0
  48.  
  49. rst.Close
  50. Set rst = Nothing
  51. Set rst = qdf.OpenRecordset
  52.  
  53. Me("txtHeading1").Caption = rst(0).Name
  54.  
  55. For intX = 2 To pageNumColumns
  56. ' Set caption of label in page header to field name.
  57. Me("txtHeading" & intX).Caption = rst(intX + pageColumnAdd - 1).Name
  58. Next intX
  59.  
  60. If pageNumColumns < conNumColumns Then
  61. For intX = pageNumColumns + 1 To conNumColumns
  62. Me("txtHeading" & intX).Caption = ""
  63. Next intX
  64. End If
  65.  
  66. ' Set control source of first text box in detail section to row header.
  67. Me("txtColumn1").ControlSource = "[" & rst(0).Name & "]"
  68.  
  69. ' Start descriptions in column 2 (the first column with a crosstab value).
  70. For intX = 2 To pageNumColumns
  71. ' Set control source of text box in detail section.
  72. Me("txtColumn" & intX).ControlSource = "[" & rst(intX + pageColumnAdd - 1).Name & "]"
  73. Next intX
  74.  
  75. If pageNumColumns < conNumColumns Then
  76. For intX = pageNumColumns + 1 To conNumColumns
  77. Me("txtColumn" & intX).ControlSource = ""
  78. Next intX
  79. End If
  80.  
  81. pageColumnAdd = pageColumnAdd + conNumColumns - 1
  82.  
  83. If intColumnCount - pageColumnAdd >= conNumColumns Then
  84. pageNumColumns = conNumColumns
  85. Else
  86. pageNumColumns = intColumnCount - pageColumnAdd
  87. End If
  88.  
  89. Loop
  90.  
  91. DoCmd.Maximize
  92.  
  93. Handle_Exit:
  94. On Error Resume Next
  95. rst.Close
  96. Set rst = Nothing
  97. Set qdf = Nothing
  98. Exit Sub
  99.  
  100. Handle_Err:
  101. MsgBox Err.Description, vbExclamation
  102. Resume Handle_Exit
  103.  
  104. End Sub
Sep 10 '13 #1
1 1355
jimatqsi
1,271 Expert 1GB
I think you've chosen a really difficult design to this report. Paging after x number of rows makes sense; paging after x number of columns is a little harder to get a hold of. That being said, you've demonstrated a pretty good understanding of how to control the various objects in a report.

Are you aware of the difference between the Format event and the Print event? Perhaps you should prepare your columns in the format event of each section. Doing all this in the Report's Open event can't work because there is not such thing as a "page" at that point in the execution.

A better approach would be to modify the report so that every detail line has a text box for every possible column. Then, in the Format event, you make invisible the columns you don't want to show and make visible the columns you do want to show. On the odd pages you show text boxes 1-11, on the even pages all the text boxes greater than 11. Same idea for the labels in the heading and totals in the footer. But you have to make visibility changes in the Format event of the Detail, Header and Footer sections; it's too late in the Print event. And doing it in the Open event gives the result you already see.

You've made a good start. I bet you'll have no trouble with this once you understand Format and Print events.

Jim
Sep 10 '13 #2

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

Similar topics

8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
by: Ima Lostsoul | last post by:
Is there a way to mak ea dynamic report from a cross tab query? Basically the query may generate a different number of columns of data depending on the conditions that are set at run time. For...
5
by: bruce24444 | last post by:
What I have is a database which tracks assigned files to a certain people which is generated by a form and then recorded into a table. Table are as follows “Staff” “Loss_Type” and...
2
by: CindySue | last post by:
Hello--I've got a query that uses DatePart("m",) to select records for a particular month, and then a report based on that query. I'd like to be able to create a field in the report that says what...
4
by: m.wanstall | last post by:
I have a crosstab query that compiles data for Months of the year. I have a stacked select query on top of that crosstab query that uses the latest 2 months data and exports it to a fixed length...
2
AccessIdiot
by: AccessIdiot | last post by:
Hello all, I have a report that is based on a crosstab query. One of the fields in the crosstab query is based on a query. It is a coded value. When I look at the crosstab query it displays the...
1
by: mfaisalwarraich | last post by:
Hi Everybody, I have an external database called Patients.mdb where i made a query called qryAdmissionDetails. now i want to run this query on a report of another database called...
1
by: JohnHo | last post by:
why won't this work? I have a form which has a text box: forms!frmCaseLog!tboCaseID the RecordSource for the form is tblCaseLog with the field I would like to print a report with details...
5
by: Mysterydave | last post by:
Hi, If I have a cross tab query which counts an and pivots on a for a , how do I add a new row heading that will sum only a certain few status's. E.g. The field has "A", "B", "C", "D". I want...
1
by: Kyrillos T | last post by:
Hello, I have created a crosstab query in Access which shows me stuff holidays calculated in days for the current year , year - 1 and year -2. Therefore there are 3 columns with headings...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.