By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

How to export table data into text file using VB6

P: 15
Hi,

By using VB6.0, I want to export database table data into text file with a tab delimiter.

My User interface has:
Drop down list box contain list of data base table name.

A path selection area, allowing the user to specify the filename, path and file type for the export. This will incorporate standard Windows functionality for allowing the user to specify file type such as tab delimited text. The path will default to the xyz server upon which my project instance is running but will allow the user to navigate to any other mapped drive.

Export button when clicked, this activates the data export using the parameters provided.

I am new to this job..please give me relevant code...

Thanks in advance
Radhakrishnan
vrradhakrishnan@gmail.com
Sep 2 '06 #1
Share this Question
Share on Google+
2 Replies


Expert
P: 92
I have the following sql statement that I use right now to export a database table into an excel spreadsheet using an automation process. Unfortunantly not all can be exported as excel files and instead need to be exported as a text file with tab delimitations. Can anyone help me change the sql statement I included below to make it instead export to a tab delimited text file. You help is welcomed. Thanks,

Dim DAODB As Database

'EXPORTS TABLE IN ACCESS DATABASE TO EXCEL
Set DAODB = OpenDatabase(strDB)

'If excel file already exists, you can delete it here
If Dir(strExcel) <> "" Then Kill strExcel

DAODB.Execute ("SELECT * INTO [Excel 8.0;DATABASE=" & strExcel & "].[" & _
strWorksheet & "] FROM " & "[" & strTable & "]")
DAODB.Close
Sep 5 '06 #2

P: 1
hi radhakrishnan,
U try this code this wil work correctly

Set rs = db.OpenRecordset("select * from " & tablelst) ' tablelst-this is yr table name
tmp_val = ""
If Not rs.EOF Then
rs.MoveLast
rcount = rs.RecordCount
rs.MoveFirst
Close
Open App.Path & "\" & tablelst & ".txt" For Output As #1
For i = 0 To rs.Fields.Count - 1
If i < rs.Fields.Count - 1 Then
tmp_val = tmp_val & rs.Fields(i).Name & vbTab
ElseIf i = rs.Fields.Count - 1 Then
tmp_val = tmp_val & rs.Fields(i).Name
End If
Next i
tmp_val = tmp_val & vbCrLf
While Not rs.EOF
For i = 0 To rs.Fields.Count - 1
tmp_val = tmp_val & rs.Fields(rs.Fields(i).Name) & vbTab
Next i
tmp_val = Mid(tmp_val, 1, Len(tmp_val) - 1)
tmp_val = tmp_val & vbCrLf
rs.MoveNext
DoEvents
Label1.Caption = rs.AbsolutePosition & "/" & rcount
Wend
Print #1, tmp_val
End If
MsgBox "Process Completed"

regards,
kalaivani murali...
Jun 28 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.