How to export table data into text file using VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RadhakrishnanR
    New Member
    • Aug 2006
    • 15

    How to export table data into text file using VB6

    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
  • Hemant Pathak
    Recognized Expert New Member
    • Jul 2006
    • 92

    #2
    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(st rDB)

    '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

    Comment

    • kalaimurali
      New Member
      • Jun 2007
      • 1

      #3
      hi radhakrishnan,
      U try this code this wil work correctly

      Set rs = db.OpenRecordse t("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).Na me & vbTab
      ElseIf i = rs.Fields.Count - 1 Then
      tmp_val = tmp_val & rs.Fields(i).Na me
      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.Fi elds(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.AbsolutePosi tion & "/" & rcount
      Wend
      Print #1, tmp_val
      End If
      MsgBox "Process Completed"

      regards,
      kalaivani murali...

      Comment

      Working...