Des,
Actually, I'm beginning to wonder why you can't use my code instead.
The block of your code in your last post presumably takes as input an array v() (given all the previous posts in this thread) containing all the lines that you have read from the file. Oh, and additionally you are pulling out the trading partner EDI identity number and the document number (and given that you get those from the invoice file you don't really need to identify them in the database lookup section) which are presumably the bits you need to look up the customer using the DataLink that you mentioned earlier.
On top of that, around that block you must have
a) a bit of code that identifies the file(s)
b) and opens the file(s)
c) reads it into v()
then, after the lookup and replacement block you must have some code that writes the modified v() back into a file (either replacing the original file, or creating a new one).
Now, my code basically does everything described above
apart from actually identifying the file we want to work on.
You just need to drop your connection string ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=KerridgeExports;Data Source=BAMBI") into cn.Open in my GetFSCDesc function.
Assuming that yiou know the file to work in is called "c:\datafile1.txt"
You can then simply call
Process "c:\datafile1.txt"
which will achieve your original goal (rewriting the invoice file with the product descriptions now included), or
Process "c:\datafile1.txt", "c:\datafile2.txt"
which will write the modified version to a new file instead.
And to get the edipartner and docnumber needs only a teeny bit of extra code, something like the following:
Code:
[blue] Dim edipartner As String
Dim docnumber As String
Dim temp() As String
Dim strEdiFile As String
strEdiFile = "c:\invoice1.txt"
Process strEdiFile ' assumes that at this point we know the filename
With New FileSystemObject
' Assuming each line in invoice file is maximum of 200 chars ... helps keep things quick
temp = Split(.OpenTextFile(strEdiFile, ForReading).Read(1000), vbCrLf)
End With
edipartner = Split(temp(0), "^")(1)
docnumber = Split(temp(4), "^")(6)
Stop ' at this point file has been updated and we know edi and doc...[/blue]