Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carriage return after last record exported

Status
Not open for further replies.

nickpin

Technical User
Jun 11, 2002
26
GB
Hi all,

I am using the ExportDelim function to export a set of records based on the result of a query. This works, and in the text file there is a carriage return after each record, except for the last one. I need to input a manual carriage return after this last record for the text file to be used successfully elsewhere.

I've looked at some threads, so I know you can use the ascii codes 10 and 13, or a function called vbCrLf (I think!) But what I'm unsure of is the code I need to put after the ExportDelim command to open the text file, go to the end of it, then insert the carriage return. Can you append the ascii commands perhaps, something using a standard >> command??!

Please note: I don't want to change the way I'm doing the export, so don't suggest it ;)

Thanks in advance,
Nick

PS - PHV apologies for not getting back to you re. my previous post about Access crashing under Server 2003 - it has now started working, and I can't explain it at all, apart from putting it down to either Server 2003 or IIS security.
 
After the exporting add these lines

Dim myFreeFileNo As Long

myFreeFileNo = FreeFile
Open "C:\Test.txt" For Append As #myFreeFileNo
Write #myFreeFileNo, vbCrLf
Close #myFreeFileNo

Just use your file name and path...
 
Thanks for the prompt reply... I seem to have made a school boy error - Access was in fact putting in a carriage return after the last record! Doh... But I would still like to know this code, and your example didn't work as expected. When running it I ended up with the following:

<last record details>
"
"
<blank line>

Any ideas why that would be?
 
Nick,

The first one is the ready one from the export. The second is those lines. I guess you opened that file in notepad and the cursor was blinking at the position to start writting....

I think is normal
 
Soz, I don't follow your reply at all. Before inserting your code I would end up with a file that looked like this:

<last record details>
<blank line> <<<< cursor would be blinking here as it's the end of the file.

Now with your code I get:

<last record details>
"
"
<blank line> <<<< cursor blinking here as it's the end of the file.

So, your code seems to have inserted two "'s on seperate rows...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top