How do I export a table to text without CR/LF. I need a flat file

G

Guest

My table has 22 94-byte records. I need to export to a single 2068-byte
record that doesn't contain any CR/LF.
 
J

John Nurick

Air code, using the WriteToFile() function at
http://www.j.nurick.dial.pipex.com/Code/index.htm

Dim rsR as DAO.Recordset
Dim S As String
Dim ErrorCode As Long

Set rsR = CurrentDB.OpenRecordset("MyTable")
With rsR
Do Until .EOF
S = S & .Fields(0).Value
Loop
.Close
End With

ErrorCode = WriteToFile(S, "C:\Temp\Myfile.txt")

If ErrorCode <> 0 Then
MsgBox "Something went wrong."
End If



On Tue, 20 Jun 2006 13:51:02 -0700, Mark Beer <Mark
 
D

Douglas J. Steele

Um, no offense John, but wouldn't it be sporting to provide them with the
code for WriteToFile as well? <g>
 
G

Guest

We ran into a problem with one line of your solution. We corrected it as
follows and everything works now. Thank for your help.

Here's the revised code:

Function WriteToText(ByVal tableName As String, ByVal exportLocation As
String)

Dim rsR As DAO.Recordset
Dim S As String
Dim ErrorCode As Long
Set rsR = CurrentDb.OpenRecordset(tableName)
Do Until rsR.EOF
S = S & rsR.Fields(0).Value
rsR.MoveNext
Loop
rsR.Close
ErrorCode = WriteToFile(S, exportLocation)
If ErrorCode <> 0 Then
MsgBox "Something Went Wrong"
Else
MsgBox "Export Complete"
End If
End Function
 

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