运行时错误'-2147217900'(80040e14)':自动化错误使用从Excel中的SQL查询中的哪里vba

我试图连接到我的SQL Serverexpression式2005从Excel VBA使用以下(从一些论坛程序复制,因为我不是很进入数据库)。 它工作完美。 只要我在sqlqueryvariables中使用WHERE(已经validation报价双和单)我得到

运行时错误'-2147217900'(80040e14)':自动化错误

类似的例程,工作从其他人拉同样的事情的数据。 我深深感谢你的帮助

谢谢

Sub ConnectTEST()

' Create a connection object. Dim cnPubs As ADODB.Connection Set cnPubs = New ADODB.Connection Dim sqlquery As String Dim rsPubs As ADODB.Recordset Set rsPubs = New ADODB.Recordset ' Provide the connection string. Dim strConn As String 'Use the SQL Server OLE DB Provider. strConn = "PROVIDER=SQLOLEDB;" sqlquery = "SELECT * FROM [Logisuite].[dbo].[EoWebStatus]" 'Connect to the Pubs database on the local server. strConn = strConn & "Server=SERVITRANSMAIn\SQLEXPRESS;Database=logisuite;Trusted_Connection=True;" 'Use an integrated login. strConn = strConn & "INTEGRATED SECURITY=sspi;" 'Now open the connection. cnPubs.Open strConn ' Create a recordset object. Set rsPubs = New ADODB.Recordset With rsPubs ' Assign the Connection object. .ActiveConnection = cnPubs ' Extract the required records. .Open sqlquery ' Copy the records into cell A1 on Sheet1. Sheet1.Range("A1").CopyFromRecordset rsPubs ' Tidy up .Close End With cnPubs.Close Set rsPubs = Nothing Set cnPubs = Nothing 

结束小组