Hi, I need to export to a text file, something like this:
Row1--Client A Details
Row2--Client A Payments Totals
Row3--Client B Details
Row4--Client B Payments Totals
.....
Footer - Sum of all payments
I almost have it working but have problems wit the "body" (Row) of the file, how can alternate the client datails (rsCustomer ) an total payments (rsPaylinkGP_VOI)...?
Here is my code:
__________________________________________-
Private Sub Command1_Click()
DoCmd.SetWarnings False
'DoCmd.RunSQL "DELETE * FROM PaylinkGP"
DoCmd.SetWarnings True
'end deleting
Dim FileName As String
FileName = "C:\PayLink\DigicelPaylink.txt"
Dim FileNumber As Long
Dim qryCurrent As QueryDef
Dim rsCustomer As Recordset
Dim rsInvoice As Recordset
Dim CustIDas As Long
Dim CustNameas As String
Dim InvID As String
Dim InvAmt As String 'pretending all are integers
Dim InvLine As String
Dim contador As Integer
Dim HeaderLine As String
'open new file
FileNumber = FreeFile
Open FileName For Output As FileNumber
'loop through invoice records nested inside vendor record loop
Set rsCustomer = CurrentDb.OpenRecordset("PaylinkGP", dbOpenSnapshot)
rsCustomer.MoveFirst
Do While Not rsCustomer.EOF 'write each vendor header
'inicia carga de datos
RecordType = rsCustomer.Fields("RecordType").Value
CustomerCountryCode = rsCustomer.Fields("CustomerCountryCode").Value
CustomerAccountNumber = rsCustomer.Fields("CustomerAccountNumber").Value
Fechadeldocumento = rsCustomer.Fields("Fechadeldocumento").Value
TransactionCode = rsCustomer.Fields("TransactionCode").Value
Numerodedocumento = rsCustomer.Fields("Numerodedocumento").Value
TransactionSequenceNumber = rsCustomer.Fields("TransactionSequenceNumber").Value
ThirdPartyTaxID = rsCustomer.Fields("ThirdPartyTaxID").Value
CurrencyCode = rsCustomer.Fields("CurrencyCode").Value
Iddeproveedor = rsCustomer.Fields("Iddeproveedor").Value
Montodeldocumento = rsCustomer.Fields("Montodeldocumento").Value
MaturityDate = rsCustomer.Fields("MaturityDate").Value
TransactionDetail1 = rsCustomer.Fields("TransactionDetail1").Value
TransactionDetail2 = rsCustomer.Fields("TransactionDetail2").Value
TransactionDetail3 = rsCustomer.Fields("TransactionDetail3").Value
TransactionDetail4 = rsCustomer.Fields("TransactionDetail4").Value
LocalTranCode = rsCustomer.Fields("LocalTranCode").Value
CustomerAccType = rsCustomer.Fields("CustomerAccType").Value
Nombreproveedor = rsCustomer.Fields("Nombreproveedor").Value
ThirdPartyAddr1 = rsCustomer.Fields("ThirdPartyAddr1").Value
ThirdPartyAddr1B = rsCustomer.Fields("ThirdPartyAddr1B").Value
ThirdPartyBankNumber = rsCustomer.Fields("ThirdPartyBankNumber").Value
ThirdPartyBankAgency = rsCustomer.Fields("ThirdPartyBankAgency").Value
ThirdPartyAcctNumber = rsCustomer.Fields("ThirdPartyAcctNumber").Value
AccType = rsCustomer.Fields("AccType").Value
ThirdPartyBF = rsCustomer.Fields("ThirdPartyBF").Value
TransactionDeliveryMethod = rsCustomer.Fields("TransactionDeliveryMethod").Value
CollActivityCode = rsCustomer.Fields("CollActivityCode").Value
ThirdPartyEmailAddr = rsCustomer.Fields("ThirdPartyEmailAddr").Value
MaximumPayment = rsCustomer.Fields("MaximumPayment").Value
'Trimidproveedor = Trim(Iddeproveedor)
UpdateType = rsCustomer.Fields("UpdateType")
'fin carga de datos
HeaderLine = RecordType & "" & CustomerCountryCode & "" & CustomerAccountNumber & "" & Fechadeldocumento & "" & TransactionCode & "" & Numerodedocumento & "" & TransactionSequenceNumber & "" & ThirdPartyTaxID & "" & CurrencyCode & "" & Iddeproveedor & "" & Montodeldocumento & "" & MaturityDate & "" & TransactionDetail1 & "" & TransactionDetail2 & "" & TransactionDetail3 & "" & TransactionDetail4 & "" & LocalTranCode & "" & CustomerAccType & "" & Nombreproveedor & "" & ThirdPartyAddr1 & "" & ThirdPartyAddr1B & "" & ThirdPartyBankNumber & "" & ThirdPartyBankAgency & "" & ThirdPartyAcctNumber & "" & AccType & "" & ThirdPartyBF & "" & TransactionDeliveryMethod & "" & CollActivityCode & "" & ThirdPartyEmailAddr & "" & MaximumPayment & "" & UpdateType
'Print #FileNumber, HeaderLine 'writes vendor name to file
rsCustomer.MoveNext
'loop through invoice records nested inside vendor record loop
Set rsPaylinkGP_VOI = CurrentDb.OpenRecordset("PaylinkGP_VOI", dbOpenSnapshot)
rsPaylinkGP_VOI.MoveFirst
Do While Not rsPaylinkGP_VOI.EOF 'write each vendor header
'Do While rsCustomer.Fields("Numerodedocumento") = rsPaylinkGP_VOI.Fields("TransactionReference")
' old CustID = rsCustomer.Fields("iddeproveedor").Value
' old CustName = rsCustomer.Fields("NombreProveedor").Value
'inicia carga de datos
vRecordType = rsPaylinkGP_VOI.Fields("RecordType").Value
vCustomerCountryCode = rsPaylinkGP_VOI.Fields("CustomerCountryCode").Value
vCustomerAccountNumber = rsPaylinkGP_VOI.Fields("CustomerAccountNumber").Value
vTransactionReference = rsPaylinkGP_VOI.Fields("TransactionReference").Value
vTransactionSequenceNumber = rsPaylinkGP_VOI.Fields("TransactionSequenceNumber").Value
vSubSequence = rsPaylinkGP_VOI.Fields("SubSequence").Value
vzInvoiceDetailDescription = rsPaylinkGP_VOI.Fields("zInvoiceDetailDescription").Value
vzBlank = rsPaylinkGP_VOI.Fields("zBlank").Value
'Trimidproveedor = Trim(Iddeproveedor)
'UpdateType = rsPaylinkGP_VOI.Fields("UpdateType")
'fin carga de datos
VOILine = vRecordType & "" & vCustomerCountryCode & "" & vCustomerAccountNumber & "" & vTransactionReference & "" & vTransactionSequenceNumber & "" & vSubSequence & "" & vzInvoiceDetailDescription & "" & vzBlank
'Print #FileNumber, HeaderLine 'writes vendor name to file
' Print #FileNumber, VOILine 'writes vendor name to file
'rsPaylinkGP_VOI.MoveNext
'Loop 'goes to next VOI RECORD
'---- TERMINA VOI -----------------------------------------------------------------------------
' rsPaylinkGP_VOI.MoveNext
' Loop 'goes to next VOI RECORD
'rsPaylinkGP_VOI.MoveNext
HeaderLine = RecordType & "" & CustomerCountryCode & "" & CustomerAccountNumber & "" & Fechadeldocumento & "" & TransactionCode & "" & Numerodedocumento & "" & TransactionSequenceNumber & "" & ThirdPartyTaxID & "" & CurrencyCode & "" & Iddeproveedor & "" & Montodeldocumento & "" & MaturityDate & "" & TransactionDetail1 & "" & TransactionDetail2 & "" & TransactionDetail3 & "" & TransactionDetail4 & "" & LocalTranCode & "" & CustomerAccType & "" & Nombreproveedor & "" & ThirdPartyAddr1 & "" & ThirdPartyAddr1B & "" & ThirdPartyBankNumber & "" & ThirdPartyBankAgency & "" & ThirdPartyAcctNumber & "" & AccType & "" & ThirdPartyBF & "" & TransactionDeliveryMethod & "" & CollActivityCode & "" & ThirdPartyEmailAddr & "" & MaximumPayment & "" & UpdateType
'Print #FileNumber, HeaderLine 'writes vendor name to file
Print #FileNumber, HeaderLine
Print #FileNumber, VOILine 'writes vendor name to file
rsPaylinkGP_VOI.MoveNext
Loop 'goes to next vendor
Loop 'goes to next VOI RECORD
'rsCustomer.MoveNext
' Final Footer
Set rsFooter = CurrentDb.OpenRecordset("Footer", dbOpenSnapshot)
rsFooter.MoveFirst
Do While Not rsFooter.EOF 'write each vendor header
' old CustID = rsCustomer.Fields("iddeproveedor").Value
RecordType = rsFooter.Fields("RecordType").Value
NumberofTransactions = rsFooter.Fields("NumberofTransactions").Value
TotalTransacAmount = rsFooter.Fields("TotalTransacAmount").Value
ThirdPartyRecords = rsFooter.Fields("ThirdPartyRecords").Value
RecordsSent = rsFooter.Fields("RecordsSent").Value
FooterLine = RecordType & "" & NumberofTransactions & "" & TotalTransacAmount & "" & ThirdPartyRecords & "" & RecordsSent
'RecordType & "" & CustomerCountryCode & "" & CustomerAccountNumber & "" & Fechadeldocumento & "" & TransactionCode & "" & Numerodedocumento & "" & TransactionSequenceNumber & "" & ThirdPartyTaxID & "" & CurrencyCode & "" & Iddeproveedor & "" & Montodeldocumento & "" & MaturityDate & "" & TransactionDetail1 & "" & TransactionDetail2 & "" & TransactionDetail3 & "" & TransactionDetail4 & "" & LocalTranCode & "" & CustomerAccType & "" & Nombreproveedor & "" & ThirdPartyAddr1 & "" & ThirdPartyAddr1B & "" & ThirdPartyBankNumber & "" & ThirdPartyBankAgency & "" & ThirdPartyAcctNumber & "" & AccType & "" & ThirdPartyBF & "" & TransactionDeliveryMethod & "" & CollActivityCode & "" & ThirdPartyEmailAddr & "" & MaximumPayment & "" & UpdateType
Print #FileNumber, FooterLine 'writes vendor name to file
rsFooter.MoveNext
Loop
rsFooter.Close
' End Final Footer
rsCustomer.Close 'when all vendor are done
'rsFooter.Close 'when all vendor are done
rsPaylinkGP_VOI.Close
Close #FileNumber 'close the text file
MsgBox "Finalizada la Exportacion"
End Sub
_____________________________________________
Thanks in advanced...
Row1--Client A Details
Row2--Client A Payments Totals
Row3--Client B Details
Row4--Client B Payments Totals
.....
Footer - Sum of all payments
I almost have it working but have problems wit the "body" (Row) of the file, how can alternate the client datails (rsCustomer ) an total payments (rsPaylinkGP_VOI)...?
Here is my code:
__________________________________________-
Private Sub Command1_Click()
DoCmd.SetWarnings False
'DoCmd.RunSQL "DELETE * FROM PaylinkGP"
DoCmd.SetWarnings True
'end deleting
Dim FileName As String
FileName = "C:\PayLink\DigicelPaylink.txt"
Dim FileNumber As Long
Dim qryCurrent As QueryDef
Dim rsCustomer As Recordset
Dim rsInvoice As Recordset
Dim CustIDas As Long
Dim CustNameas As String
Dim InvID As String
Dim InvAmt As String 'pretending all are integers
Dim InvLine As String
Dim contador As Integer
Dim HeaderLine As String
'open new file
FileNumber = FreeFile
Open FileName For Output As FileNumber
'loop through invoice records nested inside vendor record loop
Set rsCustomer = CurrentDb.OpenRecordset("PaylinkGP", dbOpenSnapshot)
rsCustomer.MoveFirst
Do While Not rsCustomer.EOF 'write each vendor header
'inicia carga de datos
RecordType = rsCustomer.Fields("RecordType").Value
CustomerCountryCode = rsCustomer.Fields("CustomerCountryCode").Value
CustomerAccountNumber = rsCustomer.Fields("CustomerAccountNumber").Value
Fechadeldocumento = rsCustomer.Fields("Fechadeldocumento").Value
TransactionCode = rsCustomer.Fields("TransactionCode").Value
Numerodedocumento = rsCustomer.Fields("Numerodedocumento").Value
TransactionSequenceNumber = rsCustomer.Fields("TransactionSequenceNumber").Value
ThirdPartyTaxID = rsCustomer.Fields("ThirdPartyTaxID").Value
CurrencyCode = rsCustomer.Fields("CurrencyCode").Value
Iddeproveedor = rsCustomer.Fields("Iddeproveedor").Value
Montodeldocumento = rsCustomer.Fields("Montodeldocumento").Value
MaturityDate = rsCustomer.Fields("MaturityDate").Value
TransactionDetail1 = rsCustomer.Fields("TransactionDetail1").Value
TransactionDetail2 = rsCustomer.Fields("TransactionDetail2").Value
TransactionDetail3 = rsCustomer.Fields("TransactionDetail3").Value
TransactionDetail4 = rsCustomer.Fields("TransactionDetail4").Value
LocalTranCode = rsCustomer.Fields("LocalTranCode").Value
CustomerAccType = rsCustomer.Fields("CustomerAccType").Value
Nombreproveedor = rsCustomer.Fields("Nombreproveedor").Value
ThirdPartyAddr1 = rsCustomer.Fields("ThirdPartyAddr1").Value
ThirdPartyAddr1B = rsCustomer.Fields("ThirdPartyAddr1B").Value
ThirdPartyBankNumber = rsCustomer.Fields("ThirdPartyBankNumber").Value
ThirdPartyBankAgency = rsCustomer.Fields("ThirdPartyBankAgency").Value
ThirdPartyAcctNumber = rsCustomer.Fields("ThirdPartyAcctNumber").Value
AccType = rsCustomer.Fields("AccType").Value
ThirdPartyBF = rsCustomer.Fields("ThirdPartyBF").Value
TransactionDeliveryMethod = rsCustomer.Fields("TransactionDeliveryMethod").Value
CollActivityCode = rsCustomer.Fields("CollActivityCode").Value
ThirdPartyEmailAddr = rsCustomer.Fields("ThirdPartyEmailAddr").Value
MaximumPayment = rsCustomer.Fields("MaximumPayment").Value
'Trimidproveedor = Trim(Iddeproveedor)
UpdateType = rsCustomer.Fields("UpdateType")
'fin carga de datos
HeaderLine = RecordType & "" & CustomerCountryCode & "" & CustomerAccountNumber & "" & Fechadeldocumento & "" & TransactionCode & "" & Numerodedocumento & "" & TransactionSequenceNumber & "" & ThirdPartyTaxID & "" & CurrencyCode & "" & Iddeproveedor & "" & Montodeldocumento & "" & MaturityDate & "" & TransactionDetail1 & "" & TransactionDetail2 & "" & TransactionDetail3 & "" & TransactionDetail4 & "" & LocalTranCode & "" & CustomerAccType & "" & Nombreproveedor & "" & ThirdPartyAddr1 & "" & ThirdPartyAddr1B & "" & ThirdPartyBankNumber & "" & ThirdPartyBankAgency & "" & ThirdPartyAcctNumber & "" & AccType & "" & ThirdPartyBF & "" & TransactionDeliveryMethod & "" & CollActivityCode & "" & ThirdPartyEmailAddr & "" & MaximumPayment & "" & UpdateType
'Print #FileNumber, HeaderLine 'writes vendor name to file
rsCustomer.MoveNext
'loop through invoice records nested inside vendor record loop
Set rsPaylinkGP_VOI = CurrentDb.OpenRecordset("PaylinkGP_VOI", dbOpenSnapshot)
rsPaylinkGP_VOI.MoveFirst
Do While Not rsPaylinkGP_VOI.EOF 'write each vendor header
'Do While rsCustomer.Fields("Numerodedocumento") = rsPaylinkGP_VOI.Fields("TransactionReference")
' old CustID = rsCustomer.Fields("iddeproveedor").Value
' old CustName = rsCustomer.Fields("NombreProveedor").Value
'inicia carga de datos
vRecordType = rsPaylinkGP_VOI.Fields("RecordType").Value
vCustomerCountryCode = rsPaylinkGP_VOI.Fields("CustomerCountryCode").Value
vCustomerAccountNumber = rsPaylinkGP_VOI.Fields("CustomerAccountNumber").Value
vTransactionReference = rsPaylinkGP_VOI.Fields("TransactionReference").Value
vTransactionSequenceNumber = rsPaylinkGP_VOI.Fields("TransactionSequenceNumber").Value
vSubSequence = rsPaylinkGP_VOI.Fields("SubSequence").Value
vzInvoiceDetailDescription = rsPaylinkGP_VOI.Fields("zInvoiceDetailDescription").Value
vzBlank = rsPaylinkGP_VOI.Fields("zBlank").Value
'Trimidproveedor = Trim(Iddeproveedor)
'UpdateType = rsPaylinkGP_VOI.Fields("UpdateType")
'fin carga de datos
VOILine = vRecordType & "" & vCustomerCountryCode & "" & vCustomerAccountNumber & "" & vTransactionReference & "" & vTransactionSequenceNumber & "" & vSubSequence & "" & vzInvoiceDetailDescription & "" & vzBlank
'Print #FileNumber, HeaderLine 'writes vendor name to file
' Print #FileNumber, VOILine 'writes vendor name to file
'rsPaylinkGP_VOI.MoveNext
'Loop 'goes to next VOI RECORD
'---- TERMINA VOI -----------------------------------------------------------------------------
' rsPaylinkGP_VOI.MoveNext
' Loop 'goes to next VOI RECORD
'rsPaylinkGP_VOI.MoveNext
HeaderLine = RecordType & "" & CustomerCountryCode & "" & CustomerAccountNumber & "" & Fechadeldocumento & "" & TransactionCode & "" & Numerodedocumento & "" & TransactionSequenceNumber & "" & ThirdPartyTaxID & "" & CurrencyCode & "" & Iddeproveedor & "" & Montodeldocumento & "" & MaturityDate & "" & TransactionDetail1 & "" & TransactionDetail2 & "" & TransactionDetail3 & "" & TransactionDetail4 & "" & LocalTranCode & "" & CustomerAccType & "" & Nombreproveedor & "" & ThirdPartyAddr1 & "" & ThirdPartyAddr1B & "" & ThirdPartyBankNumber & "" & ThirdPartyBankAgency & "" & ThirdPartyAcctNumber & "" & AccType & "" & ThirdPartyBF & "" & TransactionDeliveryMethod & "" & CollActivityCode & "" & ThirdPartyEmailAddr & "" & MaximumPayment & "" & UpdateType
'Print #FileNumber, HeaderLine 'writes vendor name to file
Print #FileNumber, HeaderLine
Print #FileNumber, VOILine 'writes vendor name to file
rsPaylinkGP_VOI.MoveNext
Loop 'goes to next vendor
Loop 'goes to next VOI RECORD
'rsCustomer.MoveNext
' Final Footer
Set rsFooter = CurrentDb.OpenRecordset("Footer", dbOpenSnapshot)
rsFooter.MoveFirst
Do While Not rsFooter.EOF 'write each vendor header
' old CustID = rsCustomer.Fields("iddeproveedor").Value
RecordType = rsFooter.Fields("RecordType").Value
NumberofTransactions = rsFooter.Fields("NumberofTransactions").Value
TotalTransacAmount = rsFooter.Fields("TotalTransacAmount").Value
ThirdPartyRecords = rsFooter.Fields("ThirdPartyRecords").Value
RecordsSent = rsFooter.Fields("RecordsSent").Value
FooterLine = RecordType & "" & NumberofTransactions & "" & TotalTransacAmount & "" & ThirdPartyRecords & "" & RecordsSent
'RecordType & "" & CustomerCountryCode & "" & CustomerAccountNumber & "" & Fechadeldocumento & "" & TransactionCode & "" & Numerodedocumento & "" & TransactionSequenceNumber & "" & ThirdPartyTaxID & "" & CurrencyCode & "" & Iddeproveedor & "" & Montodeldocumento & "" & MaturityDate & "" & TransactionDetail1 & "" & TransactionDetail2 & "" & TransactionDetail3 & "" & TransactionDetail4 & "" & LocalTranCode & "" & CustomerAccType & "" & Nombreproveedor & "" & ThirdPartyAddr1 & "" & ThirdPartyAddr1B & "" & ThirdPartyBankNumber & "" & ThirdPartyBankAgency & "" & ThirdPartyAcctNumber & "" & AccType & "" & ThirdPartyBF & "" & TransactionDeliveryMethod & "" & CollActivityCode & "" & ThirdPartyEmailAddr & "" & MaximumPayment & "" & UpdateType
Print #FileNumber, FooterLine 'writes vendor name to file
rsFooter.MoveNext
Loop
rsFooter.Close
' End Final Footer
rsCustomer.Close 'when all vendor are done
'rsFooter.Close 'when all vendor are done
rsPaylinkGP_VOI.Close
Close #FileNumber 'close the text file
MsgBox "Finalizada la Exportacion"
End Sub
_____________________________________________
Thanks in advanced...