Someone else n I made code to produce text files from a Temp Table..
But it currently only outputs by a static Text file name, I'd like to change it too .... Name the files based on the/ viarable in a column of data
i.e. and limit to 20 records exported, and start a new file for any over 20.
I.e. List1a.txt List1a.txt.. and if possible any unused Itemno filled with 0 to record 20
ColumnName
ListName1_Variable
ListName2_Variable
ListName3_Variable
ListName4_Variable
etc.
So as the Lists are added in the DB Table I don't have to amend the code or have multiple modules to add to the DB.. and
and To add a field in the Outputted file to show amount of records present..
The Current Code
Private Sub Command29_Click()
Dim oFS: Set oFS = CreateObject("Scripting.FileSystemObject")
Dim sFSpec: sFSpec = oFS.GetAbsolutePathName("C:\Program Files\iTrack\Addins\Items.txt")
Dim tsOtp: Set tsOtp = oFS.CreateTextFile(sFSpec, True)
Dim sCN: sCN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\iTrack\iTrack.mdb"
Dim oCN: Set oCN = CreateObject("ADODB.Connection")
Dim sTmpl: sTmpl = Join(Array( _
"<aDr§N§>§V1§</aDr§N§>" _
, "<rDnM§N§>§V2§</rDnM§N§>" _
, "<dEcmD§N§>§V3§</dEcmD§N§>" _
, "<sPnT§N§>§V4§</sPnT§N§>" _
), vbCrLf)
Dim dicRpl: Set dicRpl = CreateObject("Scripting.Dictionary")
dicRpl("§N§") = ""
dicRpl("§V1§") = ""
dicRpl("§V2§") = ""
dicRpl("§V3§") = ""
dicRpl("§V4§") = ""
oCN.Open sCN
Dim sSQL: sSQL = "SELECT Itemno, Itemname, UnitDec, PermNotes FROM BasicItemInfo "
Dim oRS: Set oRS = oCN.Execute(sSQL)
Dim nCount: nCount = 0
'Do Until nCount = 26
Do Until oRS.EOF
nCount = nCount + 1
dicRpl("§N§") = CStr(nCount)
dicRpl("§V1§") = oRS.Fields(0).Value
dicRpl("§V2§") = oRS.Fields(1).Value
dicRpl("§V3§") = oRS.Fields(2).Value
dicRpl("§V4§") = oRS.Fields(3).Value
Dim sOtp: sOtp = sTmpl
Dim sKey
For Each sKey In dicRpl.Keys
sOtp = Replace(sOtp, sKey, dicRpl(sKey))
Next
tsOtp.Writeline sOtp
oRS.MoveNext
Loop
oRS.Close
oCN.Close
tsOtp.Close
End Sub
The Exported info structure as Current
<aDr1>Itemno</aDr1>
<rDnM1>Itemname</rDnM1>
<dEcmD1>UnitDec</dEcmD1>
<sPnT1>PermNotes</sPnT1>
<aDr2>Itemno</aDr2>
<rDnM2>Itemname</rDnM2>
<dEcmD2>UnitDec</dEcmD2>
<sPnT2>PermNotes</sPnT2>
<aDr3>Itemno</aDr3>
<rDnM3>Itemname</rDnM3>
<dEcmD3>UnitDec</dEcmD3>
<sPnT3>PermNotes</sPnT3>
<aDr4>Itemno</aDr4>
<rDnM4>Itemname</rDnM4>
<dEcmD4>UnitDec</dEcmD4>
<sPnT4>PermNotes</sPnT4>
<aDr5>Itemno</aDr5>
<rDnM5>Itemname</rDnM5>
<dEcmD5>UnitDec</dEcmD5>
<sPnT5>PermNotes</sPnT5>
The Output as desired
<reccount>STRING</reccount>
<aDr1>Itemno</aDr1>
<rDnM1>Itemname</rDnM1>
<dEcmD1>UnitDec</dEcmD1>
<sPnT1>PermNotes</sPnT1>
<aDr2>Itemno</aDr2>
<rDnM2>Itemname</rDnM2>
<dEcmD2>UnitDec</dEcmD2>
<sPnT2>PermNotes</sPnT2>
<aDr3>Itemno</aDr3>
<rDnM3>Itemname</rDnM3>
<dEcmD3>UnitDec</dEcmD3>
<sPnT3>PermNotes</sPnT3>
<aDr4>Itemno</aDr4>
<rDnM4>Itemname</rDnM4>
<dEcmD4>UnitDec</dEcmD4>
<sPnT4>PermNotes</sPnT4>
<aDr5>Itemno</aDr5>
<rDnM5>Itemname</rDnM5>
<dEcmD5>UnitDec</dEcmD5>
<sPnT5>PermNotes</sPnT5>
<aDr6>0</aDr6>
<rDnM6>null</rDnM6>
<dEcmD6>Null</dEcmD6>
<sPnT6>Null</sPnT6>
Any Help would be greatly appreciated,, and I am a lil green,, So if you think another output format may work or any thing needs changed,, I'm more than happy to try..
But it currently only outputs by a static Text file name, I'd like to change it too .... Name the files based on the/ viarable in a column of data
i.e. and limit to 20 records exported, and start a new file for any over 20.
I.e. List1a.txt List1a.txt.. and if possible any unused Itemno filled with 0 to record 20
ColumnName
ListName1_Variable
ListName2_Variable
ListName3_Variable
ListName4_Variable
etc.
So as the Lists are added in the DB Table I don't have to amend the code or have multiple modules to add to the DB.. and
and To add a field in the Outputted file to show amount of records present..
The Current Code
Private Sub Command29_Click()
Dim oFS: Set oFS = CreateObject("Scripting.FileSystemObject")
Dim sFSpec: sFSpec = oFS.GetAbsolutePathName("C:\Program Files\iTrack\Addins\Items.txt")
Dim tsOtp: Set tsOtp = oFS.CreateTextFile(sFSpec, True)
Dim sCN: sCN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\iTrack\iTrack.mdb"
Dim oCN: Set oCN = CreateObject("ADODB.Connection")
Dim sTmpl: sTmpl = Join(Array( _
"<aDr§N§>§V1§</aDr§N§>" _
, "<rDnM§N§>§V2§</rDnM§N§>" _
, "<dEcmD§N§>§V3§</dEcmD§N§>" _
, "<sPnT§N§>§V4§</sPnT§N§>" _
), vbCrLf)
Dim dicRpl: Set dicRpl = CreateObject("Scripting.Dictionary")
dicRpl("§N§") = ""
dicRpl("§V1§") = ""
dicRpl("§V2§") = ""
dicRpl("§V3§") = ""
dicRpl("§V4§") = ""
oCN.Open sCN
Dim sSQL: sSQL = "SELECT Itemno, Itemname, UnitDec, PermNotes FROM BasicItemInfo "
Dim oRS: Set oRS = oCN.Execute(sSQL)
Dim nCount: nCount = 0
'Do Until nCount = 26
Do Until oRS.EOF
nCount = nCount + 1
dicRpl("§N§") = CStr(nCount)
dicRpl("§V1§") = oRS.Fields(0).Value
dicRpl("§V2§") = oRS.Fields(1).Value
dicRpl("§V3§") = oRS.Fields(2).Value
dicRpl("§V4§") = oRS.Fields(3).Value
Dim sOtp: sOtp = sTmpl
Dim sKey
For Each sKey In dicRpl.Keys
sOtp = Replace(sOtp, sKey, dicRpl(sKey))
Next
tsOtp.Writeline sOtp
oRS.MoveNext
Loop
oRS.Close
oCN.Close
tsOtp.Close
End Sub
The Exported info structure as Current
<aDr1>Itemno</aDr1>
<rDnM1>Itemname</rDnM1>
<dEcmD1>UnitDec</dEcmD1>
<sPnT1>PermNotes</sPnT1>
<aDr2>Itemno</aDr2>
<rDnM2>Itemname</rDnM2>
<dEcmD2>UnitDec</dEcmD2>
<sPnT2>PermNotes</sPnT2>
<aDr3>Itemno</aDr3>
<rDnM3>Itemname</rDnM3>
<dEcmD3>UnitDec</dEcmD3>
<sPnT3>PermNotes</sPnT3>
<aDr4>Itemno</aDr4>
<rDnM4>Itemname</rDnM4>
<dEcmD4>UnitDec</dEcmD4>
<sPnT4>PermNotes</sPnT4>
<aDr5>Itemno</aDr5>
<rDnM5>Itemname</rDnM5>
<dEcmD5>UnitDec</dEcmD5>
<sPnT5>PermNotes</sPnT5>
The Output as desired
<reccount>STRING</reccount>
<aDr1>Itemno</aDr1>
<rDnM1>Itemname</rDnM1>
<dEcmD1>UnitDec</dEcmD1>
<sPnT1>PermNotes</sPnT1>
<aDr2>Itemno</aDr2>
<rDnM2>Itemname</rDnM2>
<dEcmD2>UnitDec</dEcmD2>
<sPnT2>PermNotes</sPnT2>
<aDr3>Itemno</aDr3>
<rDnM3>Itemname</rDnM3>
<dEcmD3>UnitDec</dEcmD3>
<sPnT3>PermNotes</sPnT3>
<aDr4>Itemno</aDr4>
<rDnM4>Itemname</rDnM4>
<dEcmD4>UnitDec</dEcmD4>
<sPnT4>PermNotes</sPnT4>
<aDr5>Itemno</aDr5>
<rDnM5>Itemname</rDnM5>
<dEcmD5>UnitDec</dEcmD5>
<sPnT5>PermNotes</sPnT5>
<aDr6>0</aDr6>
<rDnM6>null</rDnM6>
<dEcmD6>Null</dEcmD6>
<sPnT6>Null</sPnT6>
Any Help would be greatly appreciated,, and I am a lil green,, So if you think another output format may work or any thing needs changed,, I'm more than happy to try..