How do I get the name of an ADODB recordset in VBA? DAO has a .Name property but ADODB does not seem to have that.
At first I assumed there is no such property but now, I think there has to be.
If you set the recordset of a form programmatically, and then close and save the form WITHOUT setting the recordset property to nothing, the forms recordsource property will be filled out with the name of the recordset that you opened.
Example:
I set the recordset like this
Set Me.Recordset = oDal.OpenRecordset("tblOptionList")
If I do not do
Set Me.Recordset = Nothing
tblOptionList will be in the forms recordsource property
Here is my function that opens Recordsets
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