我在本地表中使用Access 2003,稍後將傳輸並鏈接到SQL Server 2008表。我正在使用下面的代碼,但在cnn.Execute行上出現錯誤:「運行時錯誤3704:對象關閉時不允許操作」。訪問ADO:當對象關閉時不允許操作錯誤消息
sub test()
On Err GoTo Err_Sub
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim str As String
Dim strSQL As String
'Open a connection.
Set cnn = New ADODB.Connection
cnn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentDb.Name & ";" & _
"Persist Security Info=False"
strSQL = Me.RecordSource
str = Mid(strSQL, InStr(strSQL, "Where "))
strSQL = "Update myTable SET Active = False " & str
Set rs = cnn.Execute(strSQL)
If Not rs Is Nothing Then rs.Close
Exit_Sub:
Set rs = Nothing
Exit Sub
Err_Sub:
MsgBox Err.Description
Resume Exit_Sub
End Sub
它的工作,但這樣做,我不會需要rs對象。我也沒有在這個過程中使用ADO。 – Rick