Import Spreadsheet data into Access2007 using ADO/SQL

Poolie

New Member
Joined
Feb 22, 2011
Messages
1
Hi,

I am trying to upload data from an Excel spreadsheet into an Access 2007 database file, using a comnination of ADO/SQL.

I have compiled the following code (please see below), which seems to work if my spreadsheet range is less than 65336 rows

However, if more than 65336 I receive the following error message:

Run-Time error '-2147217865 (80040e37)':
The Microsoft Office Access database engine could not find the object 'SapEp1DB$T3:AU70000'.
Make sure the object exists and that you spell its name and the path name correctly.



Any help/recommendations would be much appreciated.

Code:
Option Explicit
 
Sub AccessImportNEW()
   
    Dim FirstR As Double
    Dim LastR As Double
    Dim FrameworkRange As Range
    Dim FrameworkAddress As String
   
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
   
    Dim SQL As String
   
    
    'MsgBox Application.Version
   
    'Create named range that is equal to the area you want to upload to access
    '-----------------------------------------------------------------------------
        LastR = Range("T1048576").End(xlUp).Row
       
        Select Case LastR
            Case 3
                MsgBox "NO DATA IN FRAMEWORK"
                Exit Sub
            Case Else
           
        End Select
       
        
        Set FrameworkRange = Sheets("Sapep1db").Range("T3:AU" & LastR & "")
        FrameworkAddress = FrameworkRange.Address(False, False)
        'MsgBox FrameworkAddress
       
        
    'Activate workbook
    '-----------------
        Workbooks("SapEp1DB1.xlsm").Activate
       
        'MsgBox ThisWorkbook.FullName
        Dim test As String
        'test = Sheets("sheet1").Range("A1:AB10").Address(False, False)
        'MsgBox test
       
        
    'Set SQL statement
    '-----------------
       
        
        SQL = "INSERT INTO sapdb SELECT * FROM [SapEp1DB$T3:AU70000] IN '" _
                    & ThisWorkbook.FullName & "' 'Excel 12.0 Macro;'"
       
     
    'connect to the Access database & execute SQL
    '--------------------------------------------
          
        
        Set cn = New ADODB.Connection
        With cn
            .Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                "Data [INDENT][/INDENT]Source=\\Wfcntdfs1.wfc.chevrontexaco.net\share\CTGD\GST\Finance\Comptrollers\Trading\2012\Macros\Portfolio Analyzer\SapDB.accdb;" ' & _
                "Extended Properties=""Excel 12.0 XML;HDR=Yes"";"
            .CursorLocation = adUseClient
            .Execute (SQL)
        End With
 
    
        
    'Reset variables/ranges/connections
    '-----------------------------------
        Set FrameworkRange = Nothing
        Set rs = Nothing
        cn.Close
        Set cn = Nothing
       
           
        
 End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,586
Messages
6,179,707
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top