ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run-Time Error -2147352571 (https://www.excelbanter.com/excel-programming/386306-run-time-error-2147352571-a.html)

Jani

Run-Time Error -2147352571
 
I have code that someone quite awhile ago helped me with that loads data from
an Excel spreadsheet into a SQL table and it works great. I have modified it
for another worksheet on the same file and I am getting a 'run-time error
-2147352571 (80020005) type mismatch' error and can not figure out what the
problem is. If I click End and check the SQL Table, the data actually loads.
If I click Debug, it stops at the line indicated below. I've gone back and
forth on formatting and can't see anything. Does any one have any help for me?

Thanks, Jani

Here is the code:
Sub ADOFromExcelToAccessProjectSpend()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\DT\CARMGMT\CapitalExpenditure.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "dbo_uCARProjectSpend", cn, adOpenKeyset, adLockOptimistic,
adCmdTable
' all records in a table
r = 3 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("NumBudget") = Range("A" & r).Value
.Fields("Alpha") = Range("B" & r).Value
.Fields("Description") = Range("C" & r).Value
.Fields("CapitalInvestment") = Range("D" & r).Value (if I click
'debug' this is the line highlighted)
.Fields("StartUpExpense") = Range("E" & r).Value
.Fields("CapitalOrSU") = Range("F" & r).Value etc., etc.




All times are GMT +1. The time now is 11:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com