VBA code for my report

D

Dale G

Hi,
I would like to use a modified version of this VBA code for my report, but
I’m not sure how.
The code is from the 2007 sample Northwind db. It runs in the Quarterly
report.
Private Sub Report_Open(Cancel As Integer)
On Error GoTo ErrorHandler
Dim strSQL As String
If IsNull(TempVars![Display]) Or IsNull(TempVars![Group By]) Or
IsNull(TempVars![Year]) Then
DoCmd.OpenForm "Sales Reports Dialog"
Cancel = True
Exit Sub
End If
strSQL = "TRANSFORM CCur(Nz(Sum([Sales]),0)) AS X"
strSQL = strSQL & " SELECT [" & TempVars![Display] & "] as
SalesGroupingField FROM [Sales Analysis] "
strSQL = strSQL & " Where [Year]=" & TempVars![Year]
strSQL = strSQL & " GROUP BY [" & TempVars![Group By] & "], [" &
TempVars![Display] & "]"
strSQL = strSQL & " Pivot [Sales Analysis].[Quarter] In (1,2,3,4)"
Me.RecordSource = strSQL
Me.SalesGroupingField_Label.Caption = TempVars![Display]
Done:
Exit Sub
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("Yearly Sales Report_Open", "strSQL = " & strSQL) Then
Resume
Else
Cancel = True
End If
End Sub

This is what I currently have in my reports Record source.
TRANSFORM Count(tblChecks.Result) AS CountOfResult SELECT
tblCheckType.Description FROM (tblCheckPerformed INNER JOIN (tblReport INNER
JOIN tblChecks ON tblReport.ReportID = tblChecks.ReportID) ON
tblCheckPerformed.CheckPerformedID = tblChecks.CheckPerformedID) INNER JOIN
tblCheckType ON tblCheckPerformed.CheckTypeID = tblCheckType.CheckTypeID
WHERE (((tblChecks.Result)="X")) GROUP BY tblCheckType.Description,
tblCheckType.SortOrder ORDER BY tblCheckType.SortOrder PIVOT
Format([ReportDate],"mmmm") In ("September","October","November","December");
Any help is appearciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top