• Export to Access

    Author
    Topic
    #464831

    Hello. (Excel and Access 2003)
    Has anyone an example of a procedure that exports an Excel list to a (new) Access table?
    I want to do this without using Access’s DoCmd.TransferSpreadsheet if possible.
    Thanks, Andy.

    Viewing 5 reply threads
    Author
    Replies
    • #1191691
    • #1191712

      Thank you. That looks helpful. Andy.

    • #1191716

      Hello. (Excel and Access 2003)
      Has anyone an example of a procedure that exports an Excel list to a (new) Access table?
      I want to do this without using Access’s DoCmd.TransferSpreadsheet if possible.
      Thanks, Andy.

      I was under the impression that a single sheet Excel workbook was treated as an Access table by Access.

    • #1191722

      .. although that procedure adds records to an existing table, rather than creating a new one?
      When using code to create a new table, do I have to define each field name and data type – or can
      Access assume these? Thanks, Andy.

    • #1191746

      See VBA Tips & Tricks: Create Database with ADO / ADO Create Database for code how to create your table.
      You’ll have to create the table and each field. Access can’t assume anything.

    • #1191769

      You can use something like this (depending on version):

      Code:
      Sub ExportDataFromWorkbookToAccess2003()
         ' Sample demonstrating how to export data from an Excel 97-2003 format workbook to a 2003 format database
         Dim cn As Object, strQuery As String
         Set cn = CreateObject("ADODB.Connection")
         With cn
            .Provider = "Microsoft.JET.OLEDB.4.0"
            .ConnectionString = "Data Source=C:Test1.mdb;"
            .Open
         End With
         strQuery = "SELECT Header2, Header4, Header5, Header7 INTO tblNewData FROM [Sheet1$] IN 'C:ADO Source.xls' 'Excel 8.0;HDR=Yes;'"
      
         cn.Execute strQuery
         cn.Close
         Set cn = Nothing
      End Sub
      
    Viewing 5 reply threads
    Reply To: Export to Access

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: