?
Solved

Continued question regarding error in script, previously answered by fyed

Posted on 2011-09-14
8
Medium Priority
?
366 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 85
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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

765 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