Access records to text file 
Author Message
 Access records to text file
Hi !
What's the best method to copy Access (2000 or XP) records to a text file ?
I know "getrows" but I don't understand how to use it.
Thanks.


Sat, 26 Jun 2004 22:58:56 GMT
 Access records to text file

Quote:

> Hi !
> What's the best method to copy Access (2000 or XP) records to a text file ?
> I know "getrows" but I don't understand how to use it.
> Thanks.

What type of record do you want? Comma-delimited?

Here's a generic routine that could work:

Dim rs As Recordset
Dim x As Integer
Dim N As Integer
Dim strTemp As String

' Select the data from the database
    Set rs = CurrentDb.OpenRecordset("select * from [Table Name]")
    N = FreeFile

' Open the file
    Open "c:\filename.csv" For Output As #N

' Cycle through each record, through each field
    While Not rs.EOF
        strTemp = ""
        For x = 0 To rs.Fields.Count - 1
            ' If text based, use quotes; if numeric based, don't.
            Select Case rs(x).Type
                Case dbBoolean, dbChar, dbText, dbTime, dbDate, dbMemo, dbTimeStamp
                    strTemp = strTemp & """" & rs(x) & ""","
                Case Else
                    strTemp = strTemp & rs(x) & ","
            End Select
        Next

        ' Write all but the last comma
        Print #1, Left$(strTemp, Len(strTemp) - 1)
        rs.MoveNext
    Wend

Close #N



Sun, 27 Jun 2004 04:09:42 GMT
 Access records to text file

Quote:


> > Hi !
> > What's the best method to copy Access (2000 or XP) records to a text file ?
> > I know "getrows" but I don't understand how to use it.
> > Thanks.
> What type of record do you want? Comma-delimited?
> Here's a generic routine that could work:

And this is what happens when you don't work in Access in a while. :)

The solution works for any recordset and has better formatting
capabilities, but there's also the convenient command:

DoCmd.Transfertext

For generic text export. Look it up, it's easier. :)



Mon, 28 Jun 2004 00:48:54 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Text file records comparaison against a Master text file

2. Text file records comparaison against a Master text file

3. Need Visual Basic help to export access record to text or html file template

4. Slice a record in a text file and import components into Access

5. DTS Import from a Text File with Record Info in Header Text

6. Creating Fixed-Record Length Text File - PL/SQL Command File

7. Using MS Text Drive to Access Text Files

8. Access / other database vs. text XML text file

9. Convert Text Files into Access Files

10. Convert TEXT file to ACCESS file

11. Batch file method of Converting Text File to Access Database

12. ADO exception accessing text files linked in Access


 
Powered by phpBB® Forum Software