I'm writing my first "advanced" VBA code to move Named Ranges from Excel to Access. The Named Ranges are named the same as the Access Database field names.
When I run my code, I receive the following error: "Object required". When I click "Debug", the debugger highlights DoCmd.RunSQL strSql.
The VALUES are the names of the Named Ranges. I have a feeling that's the problem, but I can't find the proper syntax to reference the Named Ranges in VBA. I really appreciate any help you can provide.
When I run my code, I receive the following error: "Object required". When I click "Debug", the debugger highlights DoCmd.RunSQL strSql.
The VALUES are the names of the Named Ranges. I have a feeling that's the problem, but I can't find the proper syntax to reference the Named Ranges in VBA. I really appreciate any help you can provide.
Code:
Sub toSpreadsDB()
Set adoCn = New ADODB.Connection
adoCn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=I:\REI\Loan Origination\_Loan Origination Tools\Calculators\Spread Database.accdb"
Dim strSql As String
strSql = "INSERT INTO SpreadData([CurrentDate], [DealName], [PropertyType], [MSA], [LoanAmount], [LoanTerm], [Amortization], [IOPeriod], [MarketLTV], [AverageLife], [MosForward], [GrossSpread], [ThreeYrTsy], [FiveYrTsy], [SevenYrTsy], [TenYrTsy], [ThirtyYrTsy], [InterpTsy], [USTRiskAdjSpread], [BPIRiskAdjSpread], [VarBPISprUSTSpr], [WgtAvgBenchSpread], [NetSpreadOverBmark]) " _
& " VALUES('" & CurrentDate & " ', '" & DealName & "', '" & PropertyType & "', '" & MSA & "', '" & LoanAmount & "', '" & LoanTerm & "', '" & Amortization & "', '" & IOPeriod & "', '" & MarketLTV & "', '" & AverageLife & "', '" & MosForward & "', '" & GrossSpread & "', '" & ThreeYrTsy & "', '" & FiveYrTsy & "', '" & SevenYrTsy & "', '" & TenYrTsy & "', '" & ThirtyYrTsy & "', '" & InterpTsy & "', '" & USTRiskAdjSpread & "', '" & BPIRiskAdjSpread & "', '" & VarBPISprUSTSpr & "', '" & WgtAvgBenchSpread & "', '" & NetSpreadOverBmark & "');"
DoCmd.RunSQL strSql
adoCn.Close
Set adoCn = Nothing
MsgBox ("New spread information added.")
End Sub