Results 1 to 2 of 2

Thread: Import excel records with VBA into a SQL data table
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Dec 2015
    Posts
    113
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Import excel records with VBA into a SQL data table

    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

  2. #2
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    49,378
    Post Thanks / Like
    Mentioned
    51 Post(s)
    Tagged
    11 Thread(s)

    Default Re: Import excel records with VBA into a SQL data table

    Are you able to complile the code?
    If not, you may be missing some required libraries that you need to add/select in VBA.
    See here: https://docs.microsoft.com/en-us/sql...ql-server-2017
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •