A family of Microsoft relational database management systems designed for ease of use.
The issue turned out to be a failure of the Export File Specification setting. The setting for a semicolon delimited CSV output file would not work when the SQL query statement was changed. The module kept failing even after the specification setting were change to match the new query results. I learned of a way to include the new setting through the use of a schema.ini file with the following three lines in the file:
[New_Perl_Split_20251106.csv]
Format=Delimited(;)
ColNameHeader=True
By added VBA code to create the schema.ini file on the fly with a subroutine, the Export File Specification settings were no longer necessary. The working code now looks like this:
Public Function CreatePerlReport()
On Error GoTo Error_Routine
'Declare variables
Dim dtGetCurrentDate As Date 'Use the date function
Dim intErrCount As Integer 'Error handling switch
Dim strReportDate As String 'Date in YYYYMMDD format to be added to perl report name
Dim strQuery As String 'Variable for SQL query statement
Dim strQueryName As String 'Variable for query name
Dim strFilePath1 As String 'Variable for the backup location that the CSV file will be stored in
Dim strFilePath2 As String 'Variable for the primary location that the CSV file will be stored in
Dim strFileName As String 'Variable for the CSV file name
Dim LogMessage As String 'Variable for error message displayed in logfile
Dim dbs As DAO.Database 'Current database
Dim rst As DAO.Recordset 'Current recordset
Dim qdf As DAO.QueryDef 'Current query
' --- Configuration ---
strReportDate = Format(Date, "yyyymmdd")
intErrCount = 0
' --- End Configuration ---
'Select EPICUNK Report query parameters
strQuery = "SELECT Format(Date(),'yyyymmdd') AS [SPLIT DATE], Original_Results.FILENAME, EPICUNK_Results.ST02, " _
& "IIf(IsNull([Original_Results]![TIN]),[Original_Results]![NPI],[Original_Results]![TIN]) AS TIN, Original_Results.NPI, " _
& "Original_Results.PAYERNAME, Original_Results.[PMT TYPE], Original_Results.[CHECK NUMBER], Original_Results.[CHECK DATE], " _
& "Original_Results.[CHECK AMOUNT], [Original_Results]![CHECK AMOUNT]-[EPICUNK_Results]![CHECK AMOUNT] AS [VARIANCE/UNK POSTED TO EPIC], " _
& "EPICUNK_Results.[CHECK AMOUNT] AS [UNK PROCEESED IN EPIC FH-IN REMIT WQ] " _
& "FROM Original_Results INNER JOIN EPICUNK_Results ON Original_Results.[CHECK NUMBER] = EPICUNK_Results.[CHECK NUMBER];"
'Delete old EPICUNK Report query results if the query exists. Then insert the new query results.
Set dbs = CurrentDb()
For Each qdf In dbs.QueryDefs
If qdf.Name = "EPICUNK_Report" Then
dbs.QueryDefs.Delete "EPICUNK_Report"
Exit For
End If
Next
Set rst = dbs.OpenRecordset(strQuery, dbOpenSnapshot)
With dbs
Set qdf = .CreateQueryDef("EPICUNK_Report", strQuery)
End With
'Select Perl Report query parameters
strQuery = "SELECT DISTINCT Format(Date(),'yyyymmdd') AS [SPLIT DATE], Original_Results.FILENAME, Original_Results.ST02, " _
& "IIf(IsNull([Original_Results]![TIN]),[Original_Results]![NPI],[Original_Results]![TIN]) AS TIN, " _
& "Original_Results.NPI AS [TIN/NPI],Original_Results.PAYERNAME, Original_Results.[PMT TYPE], Original_Results.[CHECK NUMBER], " _
& "Original_Results.[CHECK DATE], Original_Results.[CHECK AMOUNT], Null AS VARIANCE, EPICFH_Results.[CHECK AMOUNT] AS [EPIC FH], " _
& "[EPICUNK_Report].[UNK PROCEESED IN EPIC FH-IN REMIT WQ], Null AS [VARIANCE/UNK POSTED TO EPIC FH], Null AS [EPIC FH BATCH NUM] " _
& "FROM (Original_Results " _
& "LEFT JOIN EPICFH_Results ON (Original_Results.ST02 = EPICFH_Results.ST02) " _
& "AND (Original_Results.[CHECK NUMBER] = EPICFH_Results.[CHECK NUMBER]) AND (Original_Results.[CHECK DATE] = EPICFH_Results.[CHECK DATE]) AND (Original_Results.PAYERNAME = EPICFH_Results.PAYERNAME)) " _
& "LEFT JOIN EPICUNK_Report ON (Original_Results.ST02 = [EPICUNK_Report].ST02) " _
& "AND (Original_Results.[CHECK NUMBER] = [EPICUNK_Report].[CHECK NUMBER]) AND (Original_Results.[CHECK DATE] = [EPICUNK_Report].[CHECK DATE]) AND (Original_Results.PAYERNAME = [EPICUNK_Report].PAYERNAME);"
'Delete old Perl Report query results if the query exists. Then insert the new query results.
For Each qdf In dbs.QueryDefs
If qdf.Name = "Perl_Split" Then
dbs.QueryDefs.Delete "Perl_Split"
Exit For
End If
Next
Set rst = dbs.OpenRecordset(strQuery, dbOpenSnapshot)
With dbs
Set qdf = .CreateQueryDef("Perl_Split", strQuery)
End With
'Perl Report CSV file and paths configuration
strQueryName = "Perl_Split"
strFileName = strQueryName & "_" & strReportDate & ".csv"
strFilePath1 = "Z:\Production\IDX\Perl_Split_835_Files\BALANCER_REPORT\"
'strFilePath2 = "L:\CPS_PB_BillingCollectionsReimbursement\03_Cashiering-Posting-Recon\3_Reconciliation\835 EDI Perl Split Reports\"
'Send semicolon delimited CSV file to the backup location
Call CreateSchemaIniFile(strFilePath1, strFileName)
DoEvents
DoCmd.TransferText acExportDelim, , strQueryName, strFilePath1 & strFileName, True
'Send semicolon delimited CSV file to the primary location
'Call CreateSchemaIniFile(strFilePath2, strFileName)
'DoEvents
'DoCmd.TransferText acExportDelim, , strQueryName, strFilePath2 & strFileName, True
'Send email to operations and CPS balancers
MsgBox "Make sure Outlook is open in the rdp session before pressing OK."
'Call SendOutlookEmail(strFileName)
'Display end of module message
MsgBox "The Perl Split Report csv file was created and email sent. Press OK to continue."
'Closing database variables
Exit_Routine:
strQuery = ""
rst.Close
qdf.Close
dbs.Close
'Exiting function and returning control to Access
Set rst = Nothing
Set qdf = Nothing
Set dbs = Nothing
'Determine ending log statement
If intErrCount = 0 Then
LogMessage = "Create Perl Report macro completed successfully."
Else
LogMessage = "Create Perl Report macro completed."
End If
Call LogToFile(LogMessage)
Exit Function
' Save error message to the logfile and display it.
Error_Routine:
intErrCount = 1
LogMessage = " Error in CreatePerlReport " & "Error Number:" & Err.Number & " Description:" & Err.Description
Call LogToFile(LogMessage)
MsgBox "CreatePerlReport", Err.Number & ": " & Err.Description, vbCritical
Resume Exit_Routine
End Function
'Exiting function and returning control to Access
Set rst = Nothing
Set qdf = Nothing
Set dbs = Nothing
'Determine ending log statement
If intErrCount = 0 Then
LogMessage = "Create Perl Report macro completed successfully."
Else
LogMessage = "Create Perl Report macro completed."
End If
Call LogToFile(LogMessage)
Exit Function
' Save error message to the logfile and display it.
Error_Routine:
intErrCount = 1
LogMessage = " Error in CreatePerlReport " & "Error Number:" & Err.Number & " Description:" & Err.Description
Call LogToFile(LogMessage)
MsgBox "CreatePerlReport", Err.Number & ": " & Err.Description, vbCritical
Resume Exit_Routine
End Function