我正在使用带有SQL 2012后端的Access 13前端。我使用以下代码从Access调用存储过程并接收消息“ODBC调用失败”#39;。之后,我接收到“对象无效或不再设置”的消息。奇怪的是,它从SQL服务器返回正确的数据然后产生错误。当我单击确定时,我可以继续调用SP而不会出现任何进一步的错误,直到Access关闭\重新打开。下面是我的VBA代码(在调试中它会产生错误:Set Me!lstItems.Recordset = rs
此外,如果在网络上连接,它可以正常工作,如果通过VPN连接,则会发生错误。我们已经检查了VPN上的所有内容但无济于事 - 任何想法?
Private Sub cmdSearch_Click()
On Error GoTo cmdSearch_Click_Error
If IsNull(Me.txtSearch) Then
MsgBox "Please enter a value to search", vbInformation
Else
DoCmd.Hourglass True
Set CN = New ADODB.Connection
CN.ConnectionString = "DRIVER=SQL Server;SERVER=XXXXXXXXXXX;Database=XXXXXXXXXXXXXX;Trusted_Connection=YES;"
CN.Open
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = CN
.CommandText = "dbo.PVXSearch"
.CommandType = adCmdStoredProc
Set prm = .CreateParameter("@Search", adVarWChar, adParamInput, 50)
prm.Value = Me.txtSearch
.Parameters.Append prm
cmd.Execute
End With
Set rs = New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open cmd
End With
Set Me!lstItems.Recordset = rs
Me.lstItems.Requery
Set prm = Nothing
Set cmd = Nothing
Set rs = Nothing
DoCmd.Hourglass False
End If
On Error GoTo 0
Exit Sub
cmdSearch_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdSearch_Click of VBA Document Form_frmWebOrder - Please take a screenshot and email XXXXXXXXXXXXXXXXXX"
End Sub