elvenmaiden
Programmer
I am hard coding a crosstab query report that has a variable number of columns up to 16. The problem is I can only seem to print the first or last record in the recordset to the report print preview. (There is a looping structure I tried, but it is now commented out - it shows only the last record in the recordset).
Would appreciate any suggesions. Below is the code so far:
Option Compare Database
Option Explicit
'dimensions connection and recordset
Dim CurConn As New ADODB.Connection
Dim rsSalesHours As New ADODB.Recordset
Dim mintColumnCount As Integer 'holds count of columns generated by cross tab query
Dim mintColumnTotals(12) As Integer 'array to hold column totals
Dim mintDifference As Integer 'holds difference between columns selected
Dim mintTotalDifference As Integer 'holds total difference for the report
Dim mintTotal As Integer 'holds total of all columns over entire time span
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim intX As Integer
'verify that not at end of recordset
If Not rsSalesHours.EOF Then
'ensures FormatCount is not showing hold for next page
If Me.FormatCount = 1 Then
'Do Until rsSalesHours.EOF
'fill detail text boxes
For intX = 1 To mintColumnCount
Me("Detail" + Format$(intX)) = rsSalesHours(intX - 1)
Next intX
'hide unused text boxes in detail section
For intX = (mintColumnCount + 2) To 16
Me("Detail" + Format$(intX)).Visible = False
Next intX
'move to next record
rsSalesHours.MoveNext
'Loop
End If
End If
End Sub
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Dim intX As Integer
'put column headings into text boxes in page header.
For intX = 1 To mintColumnCount
Me("Head" + Format$(intX)) = rsSalesHours(intX - 1).Name
Next intX
'make next available text box Difference heading.
Me("Head" + Format$(mintColumnCount + 1)) = "Difference"
'Hide unused text boxes in page header.
For intX = (mintColumnCount + 2) To 16
Me("Head" + Format$(intX)).Visible = False
Next intX
End Sub
Private Sub Report_Open(Cancel As Integer)
'Open Recordset for use
rsSalesHours.ActiveConnection = CurrentProject.Connection
rsSalesHours.CursorType = adOpenStatic
rsSalesHours.Open "SELECT * FROM qryMonthSalesHours"
'determine number of columns in the recordsource
mintColumnCount = rsSalesHours.Fields.Count
End Sub
Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
'moves to first record in recordset
rsSalesHours.MoveFirst
'calls variable initialization routing
Call InitializeVariables
End Sub
Public Sub InitializeVariables()
Dim intCounter As Integer
'initialize array to store horizontal column totals
For intCounter = 0 To 12
mintColumnTotals(intCounter) = 0
Next intCounter
'initializes mintDifference to hold column difference
mintDifference = 0
'initializes mintTotalDifference to hold grand total of difference
mintTotalDifference = 0
'initalizes mintTotal to hold grand total of all columns
mintTotal = 0
End Sub
Would appreciate any suggesions. Below is the code so far:
Option Compare Database
Option Explicit
'dimensions connection and recordset
Dim CurConn As New ADODB.Connection
Dim rsSalesHours As New ADODB.Recordset
Dim mintColumnCount As Integer 'holds count of columns generated by cross tab query
Dim mintColumnTotals(12) As Integer 'array to hold column totals
Dim mintDifference As Integer 'holds difference between columns selected
Dim mintTotalDifference As Integer 'holds total difference for the report
Dim mintTotal As Integer 'holds total of all columns over entire time span
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim intX As Integer
'verify that not at end of recordset
If Not rsSalesHours.EOF Then
'ensures FormatCount is not showing hold for next page
If Me.FormatCount = 1 Then
'Do Until rsSalesHours.EOF
'fill detail text boxes
For intX = 1 To mintColumnCount
Me("Detail" + Format$(intX)) = rsSalesHours(intX - 1)
Next intX
'hide unused text boxes in detail section
For intX = (mintColumnCount + 2) To 16
Me("Detail" + Format$(intX)).Visible = False
Next intX
'move to next record
rsSalesHours.MoveNext
'Loop
End If
End If
End Sub
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Dim intX As Integer
'put column headings into text boxes in page header.
For intX = 1 To mintColumnCount
Me("Head" + Format$(intX)) = rsSalesHours(intX - 1).Name
Next intX
'make next available text box Difference heading.
Me("Head" + Format$(mintColumnCount + 1)) = "Difference"
'Hide unused text boxes in page header.
For intX = (mintColumnCount + 2) To 16
Me("Head" + Format$(intX)).Visible = False
Next intX
End Sub
Private Sub Report_Open(Cancel As Integer)
'Open Recordset for use
rsSalesHours.ActiveConnection = CurrentProject.Connection
rsSalesHours.CursorType = adOpenStatic
rsSalesHours.Open "SELECT * FROM qryMonthSalesHours"
'determine number of columns in the recordsource
mintColumnCount = rsSalesHours.Fields.Count
End Sub
Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
'moves to first record in recordset
rsSalesHours.MoveFirst
'calls variable initialization routing
Call InitializeVariables
End Sub
Public Sub InitializeVariables()
Dim intCounter As Integer
'initialize array to store horizontal column totals
For intCounter = 0 To 12
mintColumnTotals(intCounter) = 0
Next intCounter
'initializes mintDifference to hold column difference
mintDifference = 0
'initializes mintTotalDifference to hold grand total of difference
mintTotalDifference = 0
'initalizes mintTotal to hold grand total of all columns
mintTotal = 0
End Sub