Results 1 to 4 of 4

Thread: Export a MS acess table to excel throug VB

  1. #1

    Thread Starter
    Lively Member sameer spitfire's Avatar
    Join Date
    Nov 2001
    Location
    India
    Posts
    120

    Arrow Export a MS acess table to excel throug VB

    I have some data in msacess table which i have to export to a excel file from VB 6
    Can I do that
    Their is be excel in the user pc but thy dont have MS acess
    Can u help me to expot a Table
    It might be a recordset which has be created by Select Statement
    with Regards
    sameer Mulgaonkar

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    you can do it on a pc that has excel and access. are you saying that you want to do the export once so that the users can get at the data through excel or are you saying that you want to be able to do the export frequently from a machine that does not have access?

    you could do the export on the machine that has both and then send everyone the excel file

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Try this...

    VB Code:
    1. Private Sub ExportOneTable()
    2. 'EXPORTS TABLE IN ACCESS DATABASE TO EXCEL
    3. Dim strExcelFile As String
    4. Dim strWorksheet As String
    5. Dim strDB As String
    6. Dim strTable As String
    7. Dim objDB As Database
    8.  
    9. 'Change Based on your needs, or use
    10. 'as parameters to the sub
    11. strExcelFile = "C:\My Documents\MySpreadSheet.xls"
    12. strWorksheet = "WorkSheet1"
    13. strDB = "C:\My Documents\MyDatabase.mdb"
    14. strTable = "MyTable"
    15.  
    16. Set objDB = OpenDatabase(strDB)
    17.  
    18. 'If excel file already exists, you can delete it here
    19. If Dir(strExcelFile) <> "" Then Kill strExcelFile
    20.  
    21. objDB.Execute _
    22. "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
    23. "].[" & strWorksheet & "] FROM " & "[" & strTable & "]"
    24. objDB.Close
    25. Set objDB = Nothing
    26. End Sub

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    If you have Access why don't you just use..
    VB Code:
    1. DoCmd.OutputTo acOutputTable, "Your Table", acFormatXLS, "File Name", True
    in an Access function?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width