[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Continued question regarding error in script, previously answered by fyed

Awhile back, the script below (I changed a few fields names only) was provided to prevent pdf files from being generated if a record did not exist.  My problem is that the type of record do not exist for each Provider listed.  However, the problem is that it created a file for each Provider even if that Provider does not a record listed of the specific type that the query attached to the report ask for.  An example of database is attached.

Private Sub Command3_Click()

Dim rst As DAO.Recordset
Dim strReportName, strFileName As String
Dim strSQL As String
Dim rpt As Report

On Error GoTo ProcError

strReportName = "rptMasterReportCB"
DoCmd.OpenReport strReportName, acViewPreview, , , acHidden
Set rpt = Reports(strReportName)

strSQL = "SELECT tluFundsImport.ProvID, tblProviderAccount.ProviderName, " _
                        & "tluFundsImport.DraftDate " _
            & "FROM tblProviderAccount INNER JOIN tluFundsImport " _
            & "ON tblProviderAccount.ProvID = tluFundsImport.ProvID " _
            & "GROUP BY tluFundsImport.ProvID, tblProviderAccount.ProviderName, " _
                             & "tluFundsImport.DraftDate;"
Set rst = CurrentDb.OpenRecordset(strSQL)
rst.MoveFirst
Do While Not rst.EOF
        strFileName = "C:\Users\Eipc\Desktop\Combined " _
                    & rst!ProviderName & " " & Format(rst!DraftDate, "mm.dd.yyyy") & ".pdf"
        Debug.Print strFileName
        rpt.Filter = "ProvID = " & rst!ProvID
        rpt.FilterOn = True
        DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFileName
        rst.MoveNext
Loop
DoCmd.Close acReport, strReportName

ProcExit:
    If Not rst Is Nothing Then
        rst.Close
        Set rst = Nothing
    End If
    Exit Sub
ProcError:
    MsgBox Err.Number & vbCrLf & Err.Description, vbOKOnly, "Error exporting file"
    Debug.Print "Error exporting file", Err.Number, Err.Description
    Resume ProcExit

End Sub

Test-EFT-08-24-11--2-.accdb
0
Delores_C
Asked:
Delores_C
  • 4
  • 3
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You'd have to change your Recordset query (the strSQL Select statement) to include ONLY those records you wish to use when printing your reports. I'm not sure exactly what you mean by "the type of record do not exist for each Provider listed" so can't really suggest a fix for it, but if you build a query using that SELECT statement you should be able to get the correct records to work with.
0
 
Delores_CAuthor Commented:
The report has a query as the source.  In the field PlanType of that query, I have entered in the criteria a type "CB".  In the tluFundsImport table, only one record has this type.  I need it to only generate the record that meets that criteria.  But its creating a record for every Provider in the tblProviderAccount table.  

How do I change the Recordset query in the script?
0
 
als315Commented:
May be will be better to use same query in sub and in report? Test-EFT-08-24-11--3.accdb
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Delores_CAuthor Commented:
I tested the database from als315.  The results gives me the pdf, but if more than one provider has the type, in this case "CB" type in criteria, it puts all the providers with that type into the same pdf file.  I need it to be an independent pdf file by provider.
0
 
als315Commented:
0
 
Delores_CAuthor Commented:
Did you set the Filter in the query to match the ProvID, if yes, I know I can't filter each provider.  I have over 400 ProvID.  Also, it's creates a blank form now.  I need to eliminate file with no records.  


thanks for your patience!
0
 
als315Commented:
Query qryRPT1 is used for selecting providers. Change it to meet your requirements.
0
 
als315Commented:
May be better will be to use qryRPT (where you are selecting type) as source for qryRPT1
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now