2

I'm working on getting SQL into Excel using vba with the following script (censored to protect some db info, however the parts of the script work) When I go to compile I get the Run Time Error 430: Class Does not support Automation or does not support expected interface

I am using Excel 2007, VBA 6.5 and SQL 2005

Here's the script

Sub GetDataFromADO()

    Dim objMyConn As ADODB.Connection
    Dim objMyCmd As ADODB.Command
    Dim objMyRecordset As ADODB.Recordset

    Set objMyConn = New ADODB.Connection
    Set objMyCmd = New ADODB.Command
    Set objMyRecordset = New Recordset

    objMyConn.ConnectionString = "Provider=SQLOLEDB;SERVER=M$#$%#@@$1;DATABASE=i*&^*;Trusted_Connection=yes;HDR=yes"
    objMyConn.Open

    Set objMyCmd.ActiveConnection = objMyConn
    objMyCmd.CommandText = "use i*&^* select * from $#%.^&_d**^%_p**^^l where year(d****_date) = 2012 and month(d***_date)= 03 and deal_id < 5*******0 order by d***_id"
    objMyCmd.CommandType = adCmdText
    objMyCmd.Execute

    ActiveSheet.Range("A2").CopyFromRecordset (objMyRecordset)

End Sub
1
  • 1
    I am having difficulty seeing how that script can work. For one, the connection string does not match anything here. Which line gives the compile error? Commented Apr 10, 2012 at 8:10

1 Answer 1

2

You have initialized the objMyRecordset but never fill data into it. Then you are trying try to import data from objMyRecordset into your excel file which will not work.

First ensure that you have filled the recordset, and then only let the CopyFromRecordset be called.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.