OOPS,
Apparently I'm wrong.
I applied the file output to a test case which went fine.
Some how I am getting the weirdest error now:
Run-time error '-2147467259 (80004005)'
Method 'Open' of object'_Recordset' failed
It's so bizarre becuase there is a saved query which runs fine. Can one access the recordset of a saved query the same way you can access a live form?
[Queries]![QueryName].RecordSet or RecordSetClone?
It is using absolutely identical SQL as the saved query.
Perhaps I should post this in a new thread or is that cross or multi posting or some other religious taboo?
Here is the exact code from the sub
Sub XXXXXXX_export()
Dim header As String
Dim sSQL As String
'sSQL = "SELECT Simplicity.drug_Ptr, Simplicity.pack_ptr, Simplicity.din, DrugName.brand, DrugName.chem, DrugName.american, " _
& "calcStr([Drug.hasComplexStrength],nz([Drug.strengthMagnitude]),nz([Drug.strengthForm]),nz([Drug.stringStrength])) AS stre, " _
& "Simplicity.size, Drug.formUnits, po([prescription]) AS rx, Simplicity.pOrderNumber, Simplicity.price1, " _
& "regNum([sPrice]) AS sellingPrice, Drug.generic, Simplicity.csize " _
& "FROM DrugName INNER JOIN (Simplicity INNER JOIN Drug ON Simplicity.pOrderNumber = Drug.pONum) ON DrugName.drugNameID = Drug.nameID;"
sSQL = "SELECT Simplicity.drug_Ptr, Simplicity.pack_ptr, Simplicity.din, DrugName.brand, DrugName.chem, DrugName.american, calcStr([Drug.hasComplexStrength],nz([Drug.strengthMagnitude]),nz([Drug.strengthForm]),nz([Drug.stringStrength])) AS stre, Simplicity.size, Drug.formUnits, po([prescription]) AS rx, Simplicity.pOrderNumber, Simplicity.price1, regNum([sPrice]) AS sellingPrice, Drug.generic, Simplicity.csize FROM DrugName INNER JOIN (Simplicity INNER JOIN Drug ON Simplicity.pOrderNumber = Drug.pONum) ON DrugName.drugNameID = Drug.nameID;"
Debug.Print sSQL
header = "drug_ptr,pack_ptr,DIN,name1,name2,name3,strength, packSize,form,P/O,orderNumber,AAC,sellingPrice,generic,supplier size"
Dim cn As ADODB.Connection
Set cn = CurrentProject.Connection
Dim rs As New ADODB.Recordset
'open the greenridge export query
rs.Open sSQL, cn, adOpenForwardOnly, adLockOptimistic
'if there is no problems with it loop through the recordset and create a new file name for each 499 line block
If Not rs.EOF Then
Dim fileName As String
Dim filePath As String
Dim suffix As Byte
Dim strRecord As String
suffix = 96
filePath = "C:\data\projects\edrugsCanada\priceUpdates\"
fileName = Date
rs.MoveFirst
Do Until rs.EOF
suffix = suffix + 1 ' set to a for initial file
Open (filePath & fileName & "-" & Chr(suffix)) For Output As #1
Print #1, header
Dim i As Integer
For i = 0 To (498 Or rs.EOF)
Print #1, rs![drug_ptr] & "," & rs![pack_ptr] & "," & rs![din] & "," & rs![brand] & "," & rs![chem] & "," & rs![american] _
& "," & rs![stre] & "," & rs![Size] & "," & rs![formUnits] & "," & rs![rx] & "," & rs![pOrderNumber] & "," & rs![price1] _
& "," & rs![sellingPrice] & "," & rs![generic] & "," & rs![csize]
rs.MoveNext
Next
Close #1
Loop
End If
End Sub
Sorry it doesn't come out so clean but I didn't wat to tamper with it
-Roni
Roni Estein
[email protected]
https://www.e-drugsCanada.com