有如下代码(用于判断后台连接)
Option Compare Database
Option Explicit
Public Function CheckLinks(TableName As String) As Boolean
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
On Error Resume Next
Set rst = dbs.OpenRecordset(TableName)
rst.Close
If Err = 0 Then
CheckLinks = True
Else
CheckLinks = False
End If
End Function
已引用DAO36,编译通过。运行时发生错误,显示变量类型不匹配,将Option Explicit 、Dim dbs As Database, rst As Recordset删掉方可运行,为什么?我怀疑 Set rst = dbs.OpenRecordset(TableName)返回的是ADO记录集,导致与 Dim dbs As Database, rst As Recordset语句冲突。