Correct syntax for using Print #() function to write all fields

C

Chris Freeman

I'm doing an export to a CSV file, that needs extra rows of information. I
have the coding to print individual fields, but in stead of doing that, I
have 18 fields in the query, I want to print out all fields. i can't seem to
get it to work, so i can't seem to get it to work, and have been spending
all morning looking for examples, but everything I find is printing from
Excel. So far I have:


Set currdb = Application.CurrentProject.Connection
Set rst = New ADODB.Recordset
strSql = "SELECT * FROM qry_Reissue_Check_Req"
rst.Open strSql, currdb, adOpenDynamic, adLockOptimistic

fileout = FreeFile

Open FileName For Output As #fileout

If rst.EOF And rst.BOF Then
GoTo PROC_ERR_1
Else
Print #fileout, Chr(34) & DT & Chr(34)
L = 0
Do
Print #fileout, Chr(34) & rst.Fields![BR] & Chr(34) &
","....etc...
L = L + 1
Loop Until L = 5
FC = L * 18 '18 is the field count of the current ReIssue Chk
Req query
Print #fileout, Chr(34) & L & Chr(34) & "," & Chr(34) & FC & Chr(34)
End If

I know this is one of those simple little things, but I just can't seem to
lock it down.

Thanks for your help.
 
D

Douglas J. Steele

"can't seem to get it to work" really doesn't help us much.

What problem are you having?
 
C

Chris Freeman

Sorry Doug, been married too long, used to her understanding what I'm doing
wrong :)

I most often get Type Mismatch errors. see below:
Do While Not rst.EOF
Print #fileout, rst.Fields
L = L + 1
rst.MoveNext
Loop
Gives me error 450, invalid agruments

Do While Not rst.EOF
Print #fileout, rst.qry_Reissue_check_Req 'query name
L = L + 1
rst.MoveNext
Loop

Gives me: "member not found" error

Do While Not rst.EOF
Print #fileout, rst.DataMember
L = L + 1
rst.MoveNext
Loop
Prints blanks lines

Do While Not rst.EOF
Print #fileout, rst.Fields![*]
L = L + 1
rst.MoveNext
Loop

Gives me error 3265, "item not found in ordinal"

As i said, I have it working using Chr(34) & rst.Fields![x] & Chr(34) & ","
for each field name, but it's a huge chunk of code, and I figured that there
must be a way to use a signle array indicator to include all fields, or some
way to say next field.

Thanks
--
Chris Freeman
IT Project Coordinator


Douglas J. Steele said:
"can't seem to get it to work" really doesn't help us much.

What problem are you having?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Chris Freeman said:
I'm doing an export to a CSV file, that needs extra rows of information. I
have the coding to print individual fields, but in stead of doing that, I
have 18 fields in the query, I want to print out all fields. i can't seem
to
get it to work, so i can't seem to get it to work, and have been spending
all morning looking for examples, but everything I find is printing from
Excel. So far I have:


Set currdb = Application.CurrentProject.Connection
Set rst = New ADODB.Recordset
strSql = "SELECT * FROM qry_Reissue_Check_Req"
rst.Open strSql, currdb, adOpenDynamic, adLockOptimistic

fileout = FreeFile

Open FileName For Output As #fileout

If rst.EOF And rst.BOF Then
GoTo PROC_ERR_1
Else
Print #fileout, Chr(34) & DT & Chr(34)
L = 0
Do
Print #fileout, Chr(34) & rst.Fields![BR] & Chr(34) &
","....etc...
L = L + 1
Loop Until L = 5
FC = L * 18 '18 is the field count of the current ReIssue Chk
Req query
Print #fileout, Chr(34) & L & Chr(34) & "," & Chr(34) & FC &
Chr(34)
End If

I know this is one of those simple little things, but I just can't seem to
lock it down.

Thanks for your help.
 
D

Douglas J. Steele

Do While Not rst.EOF
strOutput = vbNullString
For lngField = 0 To rst.Fields.Count
strOutput = strOutput & "," & rst.Fields(lngField)
Next lngField
Print #fileout, strOutput
L = L + 1
rst.MoveNext
Loop


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Chris Freeman said:
Sorry Doug, been married too long, used to her understanding what I'm
doing
wrong :)

I most often get Type Mismatch errors. see below:
Do While Not rst.EOF
Print #fileout, rst.Fields
L = L + 1
rst.MoveNext
Loop
Gives me error 450, invalid agruments

Do While Not rst.EOF
Print #fileout, rst.qry_Reissue_check_Req 'query name
L = L + 1
rst.MoveNext
Loop

Gives me: "member not found" error

Do While Not rst.EOF
Print #fileout, rst.DataMember
L = L + 1
rst.MoveNext
Loop
Prints blanks lines

Do While Not rst.EOF
Print #fileout, rst.Fields![*]
L = L + 1
rst.MoveNext
Loop

Gives me error 3265, "item not found in ordinal"

As i said, I have it working using Chr(34) & rst.Fields![x] & Chr(34) &
","
for each field name, but it's a huge chunk of code, and I figured that
there
must be a way to use a signle array indicator to include all fields, or
some
way to say next field.

Thanks
--
Chris Freeman
IT Project Coordinator


Douglas J. Steele said:
"can't seem to get it to work" really doesn't help us much.

What problem are you having?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Chris Freeman said:
I'm doing an export to a CSV file, that needs extra rows of
information. I
have the coding to print individual fields, but in stead of doing that,
I
have 18 fields in the query, I want to print out all fields. i can't
seem
to
get it to work, so i can't seem to get it to work, and have been
spending
all morning looking for examples, but everything I find is printing
from
Excel. So far I have:


Set currdb = Application.CurrentProject.Connection
Set rst = New ADODB.Recordset
strSql = "SELECT * FROM qry_Reissue_Check_Req"
rst.Open strSql, currdb, adOpenDynamic, adLockOptimistic

fileout = FreeFile

Open FileName For Output As #fileout

If rst.EOF And rst.BOF Then
GoTo PROC_ERR_1
Else
Print #fileout, Chr(34) & DT & Chr(34)
L = 0
Do
Print #fileout, Chr(34) & rst.Fields![BR] & Chr(34) &
","....etc...
L = L + 1
Loop Until L = 5
FC = L * 18 '18 is the field count of the current ReIssue
Chk
Req query
Print #fileout, Chr(34) & L & Chr(34) & "," & Chr(34) & FC &
Chr(34)
End If

I know this is one of those simple little things, but I just can't seem
to
lock it down.

Thanks for your help.
 

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