Runtime 438 Error - Object Doesn't support this property method

E_DPSG

Board Regular
Joined
Jul 17, 2008
Messages
82
Hi everyone -

Running into an issue on assigning the value to the cell with the following statement:

Code:
Sheets("DASHBOARD").RangeR1C1(RowPos + i, StartPos + i).Value = rs(i)

I am calling a SQL statement to fetch the data to post against the dashboard. The SQL statement has been simplified for troubleshooting, but ultimately the worksheet is being populated via a db connection - so the end users can browse the source data for the dashboard.


here is the complete code:

Code:
Sub FetchData_QRY(ByRef ReferenceNum As String, ByRef NumFields As Integer, ByRef StartPos As Integer)
 Dim cn As Object, rs As Object, sql As String, RowPos As Integer, i As Integer
    Set cn = CreateObject("ADODB.Connection")
    With cn
        .Provider = "Microsoft.ACE.OLEDB.12.0"
        .ConnectionString = "Data Source=" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & ";" & _
        "Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
        .Open
    End With
    
    RowPos = 18 ' starting line defaulted
    
    sql = "SELECT * FROM [Sheet1$] WHERE Col1 = '" & ReferenceNum & "'"
    Set rs = cn.Execute(sql)
    
    Do
        'With Sheets("DASHBOARD")
            For i = 0 To NumFields
                Sheets("DASHBOARD").RangeR1C1(RowPos + i, StartPos + i).Value = rs(i)
            Next i
        'End With
        RowPos = RowPos + 1
        rs.MoveNext
    Loop Until rs.EOF
        
    '---Clean up---
    rs.Close
    cn.Close
    Set cn = Nothing
    Set rs = Nothing
End Sub


Any thoughts on how to correct?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi E_DPSG
try this

Code:
Sheets("DASHBOARD").cells(RowPos + i, StartPos + i).Value = rs(i)
hope this helps
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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