Export data

W

Wilmar

I want to export data (ca. 40 fields0 from a MSaccess db. with a
For-Next-loop
If I have the fields in an Array, how do I get this correct in the
ForNext-loop

Dim dbsA As Database, rst As recordset, tdfVeldnaam As TableDef
Set dbsA = Currentdb
Set rst = dbsA.OpenRecordset(StrSQL, dbOpenDynaset)
Open "XX.txt" For Output As #1
For I%=0To40
Print #1, ??????????
Next

Who can help?

Will Beumer
 
L

Larry Linson

I want to export data (ca. 40 fields)
from a MSaccess db. with a For-
Next-loop
If I have the fields in an Array, how do
I get this correct in the ForNext-loop

I don't understand about "fields in an array" as your code, slightly
modified below (but air-code, still), neither defines an array, nor appears
to use one. I've modified it so that you can write the information to the
text file (be sure to convert or format it, if it isn't text data, though)
from the recordset.

Dim dbsA As DAO.Database, rst As DAO.recordset
Set dbsA = CurrentDB
Set rst = dbsA.OpenRecordset(StrSQL, dbOpenDynaset)
If Not (rst.BOF = True And rst.EOF = True) Then
rst.MoveFirst
Open "XX.txt" For Output As #1
For I%=0To40
Print #1, rst("yourfieldname")
rst.MoveNext
If rst.EOF Then
Exit For
End If
Next
Close #1
rst.Close
Set rst = Nothing
Set dbsA = Nothing

If there's more to the "array issue", post a followup and clarify.

Larry Linson
Microsoft Access MVP
 
D

Douglas J. Steele

Larry Linson said:
I don't understand about "fields in an array" as your code, slightly
modified below (but air-code, still), neither defines an array, nor appears
to use one. I've modified it so that you can write the information to the
text file (be sure to convert or format it, if it isn't text data, though)
from the recordset.

Dim dbsA As DAO.Database, rst As DAO.recordset
Set dbsA = CurrentDB
Set rst = dbsA.OpenRecordset(StrSQL, dbOpenDynaset)
If Not (rst.BOF = True And rst.EOF = True) Then
rst.MoveFirst
Open "XX.txt" For Output As #1
For I%=0To40
Print #1, rst("yourfieldname")
rst.MoveNext
If rst.EOF Then
Exit For
End If
Next
Close #1
rst.Close
Set rst = Nothing
Set dbsA = Nothing

While I didn't understand the "fields in an array" bit either, I assumed
that there are 40 fields in the recordset, and the intent is to write all
forty fields out, not just one field.

Dim dbsA As DAO.Database, rst As DAO.recordset
Set dbsA = CurrentDB
Set rst = dbsA.OpenRecordset(StrSQL, dbOpenDynaset)
Do While Not (rst.BOF = True And rst.EOF = True)
rst.MoveFirst
Open "XX.txt" For Output As #1
For I%=0To40
Print #1, rst.Fields(I%)
Next I%
rst.MoveNext
Loop
Close #1
rst.Close
Set rst = Nothing
Set dbsA = Nothing

The line

Print #1, rst.Fields(I%)

could be

Print #1, rst.Fields(I%).Name & " = " & rst.Fields(I%)

if you wanted the name of each field you're printing out
 
W

Wilmar

Thanks for the help.

Will

Douglas J. Steele said:
While I didn't understand the "fields in an array" bit either, I assumed
that there are 40 fields in the recordset, and the intent is to write all
forty fields out, not just one field.

Dim dbsA As DAO.Database, rst As DAO.recordset
Set dbsA = CurrentDB
Set rst = dbsA.OpenRecordset(StrSQL, dbOpenDynaset)
Do While Not (rst.BOF = True And rst.EOF = True)
rst.MoveFirst
Open "XX.txt" For Output As #1
For I%=0To40
Print #1, rst.Fields(I%)
Next I%
rst.MoveNext
Loop
Close #1
rst.Close
Set rst = Nothing
Set dbsA = Nothing

The line

Print #1, rst.Fields(I%)

could be

Print #1, rst.Fields(I%).Name & " = " & rst.Fields(I%)

if you wanted the name of each field you're printing out
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top