I think I need a second loop on a recordset to produce my output file:
the rs consists of 5-600 rows of data against 6 OrderNo's and I need to start a new output when 1 field "OrderNo" changes.
Below is the function I currently have but I,m not sure if or where I can put the loop to give me the result:
Function ExportO2Pipe()
On Error GoTo Err_ExpO2Pipe
Dim O2DB As DAO.Database
Dim rstO2 As DAO.Recordset
Dim intO2 As Integer
intO2 = FreeFile()
Open "C:\ImportFiles\DEL" & Format(Now, "yymmddhhmm") & ".txt" For Output As #intO2
Set O2DB = CurrentDb()
Set rstO2 = O2DB.OpenRecordset("O2Export", dbOpenForwardOnly)
With rstO2
Print #intO2, "IBO" & "|" & "S" & ![OrderNo] & "|" & ![Sver]
Print #intO2, "IBD" & "|" & ![O2PO] & "|" & ![O2ProdC] & "|" & ![CountOfIMEI] & "|" & "U" & "|" & "S" & ![OrderNo] & "|"
Do While Not .EOF
Print #intO2, "SRN" & "|" & ![O2PO] & "|" & "S" & ![OrderNo] & "|" & ![IMEI] & "|||" & ![O2ProdC]
.MoveNext
Loop
End With
Exit_O2Pipe:
Close #intO2
rstO2.Close
Set rstO2 = Nothing
Exit Function
Err_ExpO2Pipe:
MsgBox "Error on Output Verify Data " & Err.Number & ": " & Err.Description
GoTo Exit_O2Pipe
End Function
The results I need in one output file are:
IBO|S121345|3.60
IBD|4010101010|1DELL5XN |400|U|S121345|
SRN|4010101010|S121345|354203038293595|||1DELL5XN
SRN|4010101010|S121345|354203038293603|||1DELL5XN
SRN|4010101010|S121345|354203038293785|||1DELL5XN
...............
IBO|S121346|3.60
IBD|4010101010|1DELL5XN |400|U|S121345|
SRN|4010101010|S121346|354203038293595|||1DELL5XN
SRN|4010101010|S121346|354203038293603|||1DELL5XN
SRN|4010101010|S121346|354203038293785|||1DELL5XN
................
IBO|S121347|3.60
IBD|4010101010|1DELL5XN |400|U|S121345|
SRN|4010101010|S121347|354203038293595|||1DELL5XN
SRN|4010101010|S121347|354203038293603|||1DELL5XN
SRN|4010101010|S1213475|354203038293785|||1DELL5XN
................
Steve
the rs consists of 5-600 rows of data against 6 OrderNo's and I need to start a new output when 1 field "OrderNo" changes.
Below is the function I currently have but I,m not sure if or where I can put the loop to give me the result:
Function ExportO2Pipe()
On Error GoTo Err_ExpO2Pipe
Dim O2DB As DAO.Database
Dim rstO2 As DAO.Recordset
Dim intO2 As Integer
intO2 = FreeFile()
Open "C:\ImportFiles\DEL" & Format(Now, "yymmddhhmm") & ".txt" For Output As #intO2
Set O2DB = CurrentDb()
Set rstO2 = O2DB.OpenRecordset("O2Export", dbOpenForwardOnly)
With rstO2
Print #intO2, "IBO" & "|" & "S" & ![OrderNo] & "|" & ![Sver]
Print #intO2, "IBD" & "|" & ![O2PO] & "|" & ![O2ProdC] & "|" & ![CountOfIMEI] & "|" & "U" & "|" & "S" & ![OrderNo] & "|"
Do While Not .EOF
Print #intO2, "SRN" & "|" & ![O2PO] & "|" & "S" & ![OrderNo] & "|" & ![IMEI] & "|||" & ![O2ProdC]
.MoveNext
Loop
End With
Exit_O2Pipe:
Close #intO2
rstO2.Close
Set rstO2 = Nothing
Exit Function
Err_ExpO2Pipe:
MsgBox "Error on Output Verify Data " & Err.Number & ": " & Err.Description
GoTo Exit_O2Pipe
End Function
The results I need in one output file are:
IBO|S121345|3.60
IBD|4010101010|1DELL5XN |400|U|S121345|
SRN|4010101010|S121345|354203038293595|||1DELL5XN
SRN|4010101010|S121345|354203038293603|||1DELL5XN
SRN|4010101010|S121345|354203038293785|||1DELL5XN
...............
IBO|S121346|3.60
IBD|4010101010|1DELL5XN |400|U|S121345|
SRN|4010101010|S121346|354203038293595|||1DELL5XN
SRN|4010101010|S121346|354203038293603|||1DELL5XN
SRN|4010101010|S121346|354203038293785|||1DELL5XN
................
IBO|S121347|3.60
IBD|4010101010|1DELL5XN |400|U|S121345|
SRN|4010101010|S121347|354203038293595|||1DELL5XN
SRN|4010101010|S121347|354203038293603|||1DELL5XN
SRN|4010101010|S1213475|354203038293785|||1DELL5XN
................
Steve