Solved

Continued question regarding error in script, previously answered by fyed

Posted on 2011-09-14
8
364 Views
Last Modified: 2012-05-12
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
Comment
Question by:Delores_C
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 84
ID: 36540311
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
 

Author Comment

by:Delores_C
ID: 36540343
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
 
LVL 40

Expert Comment

by:als315
ID: 36540873
May be will be better to use same query in sub and in report? Test-EFT-08-24-11--3.accdb
0
Technology Partners: 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!

 

Author Comment

by:Delores_C
ID: 36542373
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
 
LVL 40

Expert Comment

by:als315
ID: 36543004
0
 

Author Comment

by:Delores_C
ID: 36543759
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
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 36543767
Query qryRPT1 is used for selecting providers. Change it to meet your requirements.
0
 
LVL 40

Expert Comment

by:als315
ID: 36543774
May be better will be to use qryRPT (where you are selecting type) as source for qryRPT1
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question