Import excel records with VBA into a SQL data table

JannetteChristie

Board Regular
Joined
Dec 14, 2015
Messages
127
Office Version
  1. 365
I have the following code, but am getting a run-time error 438 - object dosen't support this property or method, can anyone tell me where I am going wrong please ?

Dim conn As New ADODB.Connection
Dim iRowNo As Integer
Dim cmd As ADODB.Command
Dim StrCon As String


Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
StrCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=Reporting;Data Source=dpsql02"
conn.Open StrCon
rs.Open "TenderingXLSelector", StrCon, adOpenKeyset, adLockOptimistic, adCmdTable




With Sheets("Main")
iRowNo = 10
With rs
.AddNew
Do Until .Cells(iRowNo, 3) = ""
.Fields("Oppo_number") = ActiveSheet.Range("OppoNumber")
.Fields("Product_code") = .Cells(iRowNo, 3)
.Fields("Quantity") = .Cells(iRowNo, 9)
.Fields("Selling_price") = .Cells(iRowNo, 10)
.Fields("Discount") = .Cells(iRowNo, 11)
.Fields("Order_line_value") = .Cells(iRowNo, 12)
.Fields("Process") = .Cells(iRowNo, 14)
.Fields("Dutyhead") = .Cells(iRowNo, 15)
.Fields("Flowrate") = .Cells(iRowNo, 16)
.Fields("Flowrate_per_pump") = .Cells(iRowNo, 17)
.Fields("Configuration") = .Cells(iRowNo, 18)
.Fields("Voltage") = .Cells(iRowNo, 19)
.Fields("Suction_size") = .Cells(iRowNo, 20)
.Fields("Discharge_size") = .Cells(iRowNo, 21)
.Fields("Maxhead") = .Cells(iRowNo, 22)
.Fields("Maxflow") = .Cells(iRowNo, 23)
.Fields("Motorspeed") = .Cells(iRowNo, 24)
.Fields("IP_rating") = .Cells(iRowNo, 25)
.Fields("Pressure_vessel") = .Cells(iRowNo, 26)
.Fields("Motor_KW") = .Cells(iRowNo, 27)
.Fields("FLC") = .Cells(iRowNo, 28)
.Fields("Suction_PN_rating") = .Cells(iRowNo, 29)
.Fields("Discharge_PN_rating") = .Cells(iRowNo, 30)
.Fields("Tendering_date") = Format(Now, "yyyy-mm-dd hh:mm:ss")
.Update
iRowNo = iRowNo + 1
Loop


End With
End With
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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