我写的一点代码,运行时说open无效,请指教,在线等待
Private Sub Command1_Click()
Dim conlocal As Connection
Dim rstTmp As Recordset
Dim strSou As String
strSou = "select * from output"
Set conlocal = New ADODB.Connection
conlocal.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator.CAMBRIDGE\桌面\复件 mmi\复件 print\product.mdb;Persist Security Info=False")
Set rstTmp = New ADODB.Recordset
With rstTmp
.ActiveConnection = conlocal
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockPessimistic
.Source ="select * from output"
.Open
End With
End Sub
conlocal还是rstTmp?
Dim conlocal As Connection
Dim rstTmp As Recordset
Dim strSou As String
strSou = "select * from output"
Set conlocal = New ADODB.Connection
conlocal.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and settings\Administrator.CAMBRIDGE\桌面\复件 mmi\复件 print\product.mdb;Persist Security Info=False"
Set rstTmp = New ADODB.Recordset
With rstTmp
.ActiveConnection = conlocal
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockPessimistic
.Source = "select * from output"
.Open
End With
Set conloacol = Nothing
Set rsttemp = Nothing
End Sub我已测试过了,没问题的。 open 方法,如果前面没赋值就不要用括号 ,另外 Date Souce 之间只有一个空格。
SET conlocal = New adobd.connection
conlocal.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator.CAMBRIDGE\桌面\复件 mmi\复件 print\product.mdb;Persist Security Info=False"
conlocal.CursorLocation = adUseClient
conlocal.Mode = adModeReadWrite + adModeShareDenyNone
conlocal.Open
Dim Conlocal As ADODB.Connection
Dim RstTmp As ADODB.Recordset
Dim strSou As String
strSou = "select * from DQ_TB"
Set Conlocal = New ADODB.Connection
Conlocal.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\成果录入\Chglr.mdb;Persist Security Info=False"
Set RstTmp = New ADODB.Recordset
With RstTmp
.ActiveConnection = Conlocal
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockPessimistic
.Source = strSou
.Open
End With
Set conloacol = Nothing
Set rsttemp = Nothing
End Sub
绝对测试通过的!!,那你找找原因吧。
你前面的代码没有错误,怎么现在又出现了
Persist Security Info=False 中间都是只有一个空格,你也用了两个
应该是Persist Security Info=False
另外也要注意路径中的空格