在VBA中从SQL Server提取数据
|
您好,下面是我的代码,我无法从SQL服务器中获取数据,
其投掷错误为
Compiler error : object required.
连接没有问题,连接成功。
请更正我的代码,帮我解决这个问题
Private Sub CommandButton1_Click()
Set SQLConn = CreateObject(\"ADODB.Connection\")
SQLConn.Open \"provider =sqloledb; Data Source = xxxx; Initial Catalog = jjjj; User Id = yyyy; Password = zzzz\"
MsgBox \"Connection Succesful\"
Set SQLData = CreateObject(\"ADODB.Recordset\")
With SQLData
\' Assign the Connection object.
.ActiveConnection = SQLConn
\' Extract the required records.
.Open \"select invoice_num, invoice_date, invoice_amount from im_invoice where billing_account = \'HS0076A\' and invoice_date =\'01-apr-2011\'\"
\' Copy the records into cell A1 on Sheet1.
Sheet1.Range(\"A1\").CopyFromRecordset SQLData
\' Tidy up
.Close
End With
SQLConn.Close
Set SQLData = Nothing
Set SQLConn = Nothing
End Sub
谢谢
谢谢你的工作.... :)
没有找到相关结果
已邀请:
2 个回复
捻盒愧杯
购藏盗码韦
谢谢!