Well, that didn't work either. I'll post more of the code so you can see what I'm trying to accomplish. Again, I need to import this file (actually a collection of files, but the tables are already loaded for now, so I can get the other file imports working after this is fixed). Then I need to do some things with the data in the table to get an export file. Here's the code...
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data " & _
"Source=C:\Documents and Settings\apprss\Desktop\Purchasing Work\PurchasingP2P.accdb;" & _
"Persist Security Info=False;"
' SQL statement to run
sqlVoucherNumber = "select * from tblVoucherNumber"
sqlPaymentHeader = "select * from tblPaymentHeader"
sqlBatchSum = "Select SUM(GrossAmount) As BatchAmount From tblPaymentHeader"
Dim cn, cmd1, cmd2, cmd3, cmd4
' Create ADO Connection/Command objects
set cn = createobject("ADODB.Connection")
set cmd1 = createobject("ADODB.Command")
set cmd2 = createobject("ADODB.Command")
set cmd3 = createobject("ADODB.Command")
set cmd4 = createobject("ADODB.Command")
' Open connection
cn.open connectionString
Dim appAccess
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase "C:\Documents and Settings\apprss\Desktop\Purchasing Work\PurchasingP2P.accdb"
If (objFSO.FileExists(varPmtDetail)) Then
appAccess.DoCmd.RunSavedImportExport "Import-tblPaymentDetail"
End If
' Associate connection object with command object
cmd1.ActiveConnection = cn
cmd2.ActiveConnection = cn
cmd3.ActiveConnection = cn
cmd4.ActiveConnection = cn
' Set the SQL statement of the command object
cmd1.CommandText = sqlVoucherNumber
cmd2.CommandText = sqlPaymentHeader
cmd3.CommandText = sqlBatchSum
cmd4.CommandText = sqlUpdProcessed
Dim rs1, rs2, rs3
' Execute query
set rs1 = cmd1.execute
set rs2 = cmd2.execute
set rs3 = cmd3.execute
Dim varBatchAmount
varBatchAmount = (round(rs3("BatchAmount"),2)) * 100
varBatchAmount = RightPad(varBatchAmount, 17, "0")
Dim var1Brec
'Format and write 1B record (batch header)
varBatchID = rs1("VoucherPrefix") & vMo & vDay
var1Brec = "1B" & varBatchID & "01077" & varBatchAmount
objOutputFile.WriteLine(var1Brec)
Dim varVoucherNumJustified, varVoucherPrefix, varVoucherNum, varInvoiceDate, _
varAmount, var1Grec, varInvoiceType, varYear, varPmtIDsplit, varPmtID
while rs2.EOF <> true and rs2.BOF <> True
'format voucher number
varVoucherPrefix = rs1("VoucherPrefix") 'get Voucher prefix from Voucher number table
varPmtID = rs2("PaymentID") 'Save PaymentID to variable for UPDATE query
varPmtIDsplit = split(rs2("PaymentID"), "-") 'Split Paymet ID for deriving voucher number
varVoucherNumJustified = RightPad( varPmtIDsplit(1), 5, "0" ) 'Right-justify voucher suffix
varVoucherNum = varVoucherPrefix & varVoucherNumJustified 'Combine voucher prefix and suffix to create voucher number
msgbox("Voucher: " & varVoucherNum)
sqlStr = "UPDATE tblPaymentHeader SET [Voucher] = '" & varVoucherNum & "' WHERE [PaymentID] = '" & varPmtID & "'"
appAccess.DoCmd.RunSQL sqlStr
varVendor = RightPad( rs2("RemittanceLocation"), 9, "0" )
varDate = CDate(rs2("InvoiceDate"))
'msgbox varDate
varYear = Mid(DatePart("yyyy",varDate),3,2)
varInvoiceDate = RightPad( DatePart("m",varDate), 2, "0" ) & RightPad( DatePart("d",varDate), 2, "0" ) & varYear
if ( rs2("GrossAmount") < 0 ) then
varAmount = RightPad( ((round(rs2("GrossAmount"),2)) * -100), 15, "0" )
varInvoiceType = "4"
else
varAmount = RightPad( ((round(rs2("GrossAmount"),2)) * 100), 15, "0" )
varInvoiceType = "1"
end if
'format and output 1G record
var1Grec = "1G" & varBatchID & rs2("Voucher") & varInvoiceType & varVendor & LeftPad( rs2("InvoiceNumber"), 25, " " ) & varInvoiceDate & varAmount
objOutputFile.WriteLine(var1Grec)
'UPDATE PROCESSED FLAG IN PAYMENT HEADER TABLE
sqlStr = "(UPDATE tblPaymentHeader SET Processed=True Where Voucher = '" & varVoucherNum & "')"
appAccess.DoCmd.RunSQL sqlStr
rs2.movenext
wend
Thanks!
Scott