我正在使用带有本地表的 Access 2003,该表稍后将被传输并链接到 SQL Server 2008 表。我正在使用以下代码,但收到错误:cnn.Execute 行上的“运行时错误 3704:对象关闭时不允许操作”。
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