Solved

Continued question regarding error in script, previously answered by fyed

Posted on 2011-09-14
8
359 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
  • 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 39

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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 39

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 39

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 39

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now