3
你好下面是我的代码,我不能够从我的SQL服务器, 其投掷误差数据从SQL Server获取在VBA
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
谢谢
谢谢你的工作.... :)
您好!如果你发现如何使它工作,你能接受帮助你的答案吗? :)您可以通过点击答案旁边的复选标记来接受答案。 – hammythepig 2017-02-06 22:47:21