K
Kensgracie
The following code works great. Until I try to add two more fields. I just
can’t seem to get it right. It's because of the reformatting, I think. The
fields, in the linked txt file are data type Text.
I want to add to the INSERT stmt AcctNbr and EntryDt. The Select stmt needs
something like;
& InFile & (Right,(AcctNbr,6) AS AcctNbr), & InFile & (Mid(EntryDtA,5,2) &
“-“ & Right(EntryDtA,2) & â€-“ & Left(EntryDtA,4)) As EntryDt).
I’ve tried a number of different combinations and have read quite a few
posts but with no success.
Can someone please clue me in on how to get these two fields to work?
Thanks.
Dim strSQL As String
Dim InFile As String
Dim iLoop As Long
Dim DbAny As DAO.Database
Set DbAny = CurrentDb()
'Start loop at 2. The first file was has already been exported to GLYr5 in
SQL, and that table linked to this db.
For iLoop = 2 To 52
InFile = "D" & Format(iLoop)
' This appends data to the SQL table GLYr5.
strSQL = "INSERT INTO GLYr5 ( CoCd, AcctTyp, ProfCntr, CostCntr, FY,
Period, DocNbr, DocTyp, LnNbr, DrCr, " & _
"Amt, TranCd, RefDocNbr, RevDocNbr, DocHdrTxt, ClearingEntryDt,
DocNbrofClearingDoc, PostKey, AssgnmntNbr, " & _
"ItemTxt, OrderNbr, BillingDoc, NetPmtPeriod, ReasonCodeforPayments,
NetPmt )" & _
"SELECT " & InFile & ".CoCd, " & InFile & ".AcctTyp, " & InFile &
".ProfCntr, " & InFile & ".CostCntr, " & _
InFile & ".FY, " & InFile & ".Period, " & InFile & ".DocNbr, " & InFile &
".DocTyp, " & InFile & ".LnNbr, " & _
InFile & ".DrCr, " & InFile & ".Amt, " & InFile & ".TranCd, " & InFile &
".RefDocNbr, " & InFile & ".RevDocNbr, " & _
InFile & ".DocHdrTxt, " & InFile & ".ClearingEntryDt, " & InFile &
".DocNbrofClearingDoc, " & InFile & ".PostKey, " & _
InFile & ".AssgnmntNbr, " & InFile & ".ItemTxt, " & InFile & ".OrderNbr,
" & InFile & ".BillingDoc, " & _
InFile & ".NetPmtPeriod, " & InFile & ".ReasonCodeforPayments, " & InFile
& ".NetPmt FROM " & _
InFile & ""
DbAny.Execute strSQL, dbFailOnError
Next iLoop
can’t seem to get it right. It's because of the reformatting, I think. The
fields, in the linked txt file are data type Text.
I want to add to the INSERT stmt AcctNbr and EntryDt. The Select stmt needs
something like;
& InFile & (Right,(AcctNbr,6) AS AcctNbr), & InFile & (Mid(EntryDtA,5,2) &
“-“ & Right(EntryDtA,2) & â€-“ & Left(EntryDtA,4)) As EntryDt).
I’ve tried a number of different combinations and have read quite a few
posts but with no success.
Can someone please clue me in on how to get these two fields to work?
Thanks.
Dim strSQL As String
Dim InFile As String
Dim iLoop As Long
Dim DbAny As DAO.Database
Set DbAny = CurrentDb()
'Start loop at 2. The first file was has already been exported to GLYr5 in
SQL, and that table linked to this db.
For iLoop = 2 To 52
InFile = "D" & Format(iLoop)
' This appends data to the SQL table GLYr5.
strSQL = "INSERT INTO GLYr5 ( CoCd, AcctTyp, ProfCntr, CostCntr, FY,
Period, DocNbr, DocTyp, LnNbr, DrCr, " & _
"Amt, TranCd, RefDocNbr, RevDocNbr, DocHdrTxt, ClearingEntryDt,
DocNbrofClearingDoc, PostKey, AssgnmntNbr, " & _
"ItemTxt, OrderNbr, BillingDoc, NetPmtPeriod, ReasonCodeforPayments,
NetPmt )" & _
"SELECT " & InFile & ".CoCd, " & InFile & ".AcctTyp, " & InFile &
".ProfCntr, " & InFile & ".CostCntr, " & _
InFile & ".FY, " & InFile & ".Period, " & InFile & ".DocNbr, " & InFile &
".DocTyp, " & InFile & ".LnNbr, " & _
InFile & ".DrCr, " & InFile & ".Amt, " & InFile & ".TranCd, " & InFile &
".RefDocNbr, " & InFile & ".RevDocNbr, " & _
InFile & ".DocHdrTxt, " & InFile & ".ClearingEntryDt, " & InFile &
".DocNbrofClearingDoc, " & InFile & ".PostKey, " & _
InFile & ".AssgnmntNbr, " & InFile & ".ItemTxt, " & InFile & ".OrderNbr,
" & InFile & ".BillingDoc, " & _
InFile & ".NetPmtPeriod, " & InFile & ".ReasonCodeforPayments, " & InFile
& ".NetPmt FROM " & _
InFile & ""
DbAny.Execute strSQL, dbFailOnError
Next iLoop