Results 1 to 9 of 9

Thread: [RESOLVED] export from ms access .mdb to excel .csv

  1. #1

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Resolved [RESOLVED] export from ms access .mdb to excel .csv

    how do you export the ms access recordset data into an excel .csv?


    and one more thing how do you create a .csv/.mdb file at runtime
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: export from ms access .mdb to excel .csv

    Are you connecting to your db from VB6 using ADO? What versions of Access and Excel are you using?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: export from ms access .mdb to excel .csv

    sorry i forgot to include that.

    VB6 using ADODB

    excel and access 2000
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: export from ms access .mdb to excel .csv

    Ok, then if you have a ADO recordset that is the source for exporting to Excel then you can just use the .CopyFromRecordset method.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: export from ms access .mdb to excel .csv

    thanks robdog
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: export from ms access .mdb to excel .csv

    If you need anymore help with Excels .CopyFromRecordset method let me know. I can write a small example if you need it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: export from ms access .mdb to excel .csv

    i don't mind a little more help
    Last edited by modpluz; Oct 18th, 2005 at 05:19 PM.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: export from ms access .mdb to excel .csv

    Ok, here is how you connect to your Access db, populate a recordset, create a new Excel workbook, and copy the entire recordset into sheet1.
    VB Code:
    1. Option Explicit
    2. 'Add a reference to MS Excel xx.0 Object Library
    3. 'Add a reference to MS ActiveX Data Objects 2.x Library
    4. Private Sub Command1_Click()
    5.     Dim oRs As ADODB.Recordset
    6.     Dim oCnn As ADODB.Connection
    7.     Dim oApp As Excel.Application
    8.     Dim oWB As Excel.Workbook
    9.     Dim i As Integer
    10.     'Connect to your Access db
    11.     Set oCnn = New ADODB.Connection
    12.     oCnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\RobDog888.mdb;Persist Security Info=False"
    13.     oCnn.Open
    14.     'Create your recordset
    15.     Set oRs = New ADODB.Recordset
    16.     oRs.Open "SELECT * FROM Table1;", oCnn, adOpenKeyset, adLockReadOnly, adCmdText
    17.     'Create an instance of Excel and add a new blank workbook
    18.     Set oApp = New Excel.Application
    19.     oApp.Visible = False
    20.     Set oWB = oApp.Workbooks.Add
    21.     'Add the field names as column headers (optional)
    22.     For i = 0 To oRs.Fields.Count - 1
    23.         oWB.Sheets(1).Cells(1, i + 1).Value = oRs.Fields(i).Name
    24.     Next
    25.     oWB.Sheets(1).Range("1:1").Font.Bold = True
    26.     oWB.Sheets(1).Cells(2, 1).CopyFromRecordset oRs
    27.     oRs.Close
    28.     Set oRs = Nothing
    29.     oCnn.Close
    30.     Set oCnn = Nothing
    31.     oWB.Close SaveChanges:=True, FileName:="D:\Test.xls"
    32.     Set oWB = Nothing
    33.     oApp.Quit
    34.     Set oApp = Nothing
    35. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: [RESOLVED] export from ms access .mdb to excel .csv

    found something, after creating the .CSV it opens it and also open a new .XLS(named Book1) file containing all tables and field defined in the SQL statement.

    why does that happens and how can i stop it.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

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