Printing Reports Automatically from VB6
I have a report (based on a query which has one parameter (Date)) stored in Access
I have code that will print the report directly from VB6
I am trying to get the report to print and pass the date parameter in code but I still keep getting the parameter box prompt.
Here is the code:
Code:
'Call the procedure
PrintEndOfDayReport "DOS= " & Format$(DTPicker1, "dd/MMM/yy")
Private Sub PrintEndOfDayReport(strParam As String)
Dim dbName As String
Dim rptName As String
Dim Preview As Long
Const acNormal = 0
Const acPreview = 2
On Error GoTo ErrorTrap
Set objAccess = New Access.Application
'Set the path to the database
dbName = App.Path & "\Customers.mdb"
rptName = "rptEndOfDay"
Preview = acNormal
'acPreview will show a print preview and open up the db
With objAccess
'open the db
.OpenCurrentDatabase filepath:=dbName
If Preview = acPreview Then
.Visible = True
.DoCmd.OpenReport rptName, Preview
Else
.DoCmd.OpenReport rptName, , strParam
End If
End With
Set objAccess = Nothing
Exit Sub
ErrorTrap:
MsgBox "An error has occurred in the procedure PrintEndOfDayReport!" _
& vbNewLine & "The error number is: " & Err.Number _
& vbNewLine & "The error description is: " & Err.Description
End Sub
Re: Printing Reports Automatically from VB6
Quote:
.DoCmd.OpenReport rptName, , strParam
is the empty parameter required?
Re: Printing Reports Automatically from VB6
The original access query is below:
SELECT tblSales.CustomerName, tblSales.Make, tblSales.Model, tblSales.AmountDue, tblPaymentTypes.PaymentTypeDesc
FROM tblPaymentTypes INNER JOIN tblSales ON tblPaymentTypes.PaymentType = tblSales.PaymentType
WHERE (((tblSales.DOS)=[Enter Date For Report]));
The report that I want to run is based on the above query.
I have read in some posts that you can pass a parameter to the report. But in the code that I posted showing the parameter passed in - does not stop the dialog box opening asking for the date.