【发布时间】:2015-07-23 23:59:45
【问题描述】:
如何在 VBA 中获取 ADODB 记录集的名称? DAO 有一个 .Name 属性,但 ADODB 似乎没有。
起初我认为没有这样的属性,但现在,我认为必须有。
如果您以编程方式设置表单的记录集,然后关闭并保存表单而不将记录集属性设置为空,则表单记录源属性将填写您打开的记录集的名称。
例子:
我这样设置记录集
Set Me.Recordset = oDal.OpenRecordset("tblOptionList")
如果我不这样做
Set Me.Recordset = Nothing
tblOptionList 将在表单记录源属性中
这是我打开记录集的函数
Public Function OpenRecordset(ByVal Tablename As String) As ADODB.Recordset
Dim FilePath As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
FilePath = GetFilePath(Tablename)
'Try to get a connection
Connection
If ConnOpen Then
Set rs.ActiveConnection = pDbConn
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open Tablename
If pEnableOffline Then
SaveOffline rs, Tablename
End If
Else
'No connection, check for offline availablility
If Dir(FilePath) <> "" And pEnableOffline Then
rs.Open FilePath
Else
MsgBox "No Offline data and Server is Unavailable"
Exit Function
End If
End If
Set OpenRecordset = rs
End Function
【问题讨论】: