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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create comma-delimited file using Access Database 1

Status
Not open for further replies.

morechocolate

Technical User
Apr 5, 2001
225
US
I know how to use ADO to work with Access Databases, but I need to create a comma-delimited file using the information in the recordset and I am not too sure how to do that.

I am aware of the for Output command for sequential files, but it requires Write# var1,var2,var3...

Is that the best way if you have several fields in the recordset?

Thanks

mc
 
This is how to set it up:

Dim cn As New adodb.Connection
Dim rst As New adodb.Recordset
Dim sSql As String
Dim strA As String
Dim fso As New Scripting.FileSystemObject
Dim txtFile As Scripting.TextStream

With cn
.ConnectionString = mksConnectionString
.Open
End With

sSql = "SELECT * from yourtable"
rst.Open sSql, cn
Set txtFile = fso.CreateTextFile(App.Path & "\youroutputfile.txt", True)

txtFile.Write (rst.GetString(adClipString, , "}", _
vbCrLf, ""))

You do need the scrrnnl.dll to do this. It can be downloaded from Microsoft at no charge. They just forgot to have this in the VB release.

 
Also, look at the TransferText Method.
MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
I am fairly new with macros and VB, and I am trying automate a transfer text from a query to a word document. I tried creating a macro to open the query, select the last record and transfertext, however I keep getting an error message stating that the database or object is read-only. I cannot figure out how to remedy this problem. Any assistance will be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top