Results 1 to 3 of 3

Thread: Printing Reports Automatically from VB6

  1. #1
    Member
    Join Date
    Nov 10
    Posts
    40

    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

  2. #2
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,524

    Re: Printing Reports Automatically from VB6

    .DoCmd.OpenReport rptName, , strParam
    is the empty parameter required?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Member
    Join Date
    Nov 10
    Posts
    40

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •