Solved

Continued question regarding error in script, previously answered by fyed

Posted on 2011-09-14
8
360 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vbscript or powershell to give me a logged on user from an IP address 4 50
Problem to With line 4 43
MS Access Tables Linking 6 42
how to link subforms ms/access VBA 6 30
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

867 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

15 Experts available now in Live!

Get 1:1 Help Now