Blank line at End of file (Print #1)

F

FBxiii

Hi. I am using VBA to create a file by writing records to it using Open ....
For Output as #1

Everything writes to file fine but a blank line appears at the end. Is
there any way of stopping this as the file will be rejected by another system
if it contains a blank record.

Cheers,
Steve
 
D

Douglas J. Steele

How are you writing to the file? Specifically, what's the last Print or
Write statement in your code?
 
J

John Nurick

Hi Steve,

When you write records to the file using either Write # or Print #,
VBA automatically ends each record with a CR+LF.

So the file ends with the CR+LF at the end of the last record; some
software reads this as a blank line.

If you're using Print #, you can suppress the CR+LF by terminating the
statement with a semicolon, e.g.

Print #lngFN, strRecord ;

so you could write a loop like this:

boolFirstRecord = True
Do Until rsR.EOF 'iterate through recordset
If Not boolFirstRecord Then
Print #lngFN, 'prints CR+LF
End If
boolFirstRecord = False
Print #lngFN, blah blah 'print record
rsr.MoveNext 'next record
Loop

to omit the CR+LF after the last record.
 
F

FBxiii

Hi.

Thanks for the replies.

I have modified my code to use the semi-colon on the last record by using a
record count:

If intCurRecord < intTotRecords Then
Print #1, strFileText
Else
Print #1, strFileText;
End If

Thanks!
Steve.
 

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