
Exporting Acces2K table (or query) to separate text files
I am trying to write VBA code that selects records from a query using a value from another query, then exports each resultset to a fixed length text file.
I have already built the code to loop through the first query/table and return the correct parameter. I have also built the export code (including export definitions) but I am having difficulty "opening" the query with a parameter. (Once I get the query (with parameter) opened, I'm pretty sure I can export it just fine.)
==========================
qSchools: discrictID eFlag
1 True
2 True
5 True
qExport: districtID name address amount
1
2
3
4
5
==========================
Sub Export()
Dim rs1, rs2 As ADODB.Recordset
Set rs1 = New ADODB.Recordset
rs1.Open "qSchools", CurrentProject.Connection, adOpenKeyset
While Not rs1.EOF
' The 1st iteration: rs1![districtID] = 1
' The 2nd iteration: rs1![districtID] = 2
' The 3rd iteration: rs1![districtID] = 5 , ...etc...
' I NEED CODE HERE to open "qExport"
' Where qExport.districtID = rs1![districtID]
' to prepare for exporting to file "g:\school" & rs1![District] & ".txt"
' I can't seem to declare and open another New ADODB.Recordset
' The following two lined of code won't work...
Set rs2 = New ADODB.Recordset '***This line errors!
rs2.Open "qExport" Where qExport.districtID = rs1![districtID]
DoCmd.TransferText acExportFixed, "Export_Spec", "qExport", & _
"G:\School" & rs1![districtID] & ".txt", 0
rs1.MoveNext
Wend
rs1.Close
End Sub
==========================
It seems that I can't delcare and open (and nest) another recordset within the the first recordset I've opened.
Any help would be greatly appreciated!
-jim