Check if DAO recordset is open

K

Ken Snell

My thought is to check a propery of the recordset and see if you get an
error that indicates that the recordset isn't available. For example,

On Error Resume Next
Dim blnTest As Boolean
blnTest = RecordsetName.EOF
If Err.Number <> 0 Then
' recordset isn't open or assigned == likely error 3420
End If


You also could loop through the Recordsets collection to see if the
recordset is there, for example checking for its name (which may not be
unique, as it's the table name or query name or SQL string of each open
recordset).
 
A

Allen Browne

This example shows how to loop through all the open recordsets in the open
databases to get a count:

Function CountOpenRecordsets() As Long
Dim ws As DAO.Workspace
Dim lngKt As Long
Dim i As Integer

Set ws = DBEngine(0)
For i = 0 To ws.Databases.Count - 1
lngKt = lngKt + ws(i).Recordsets.Count
Next

CountOpenRecordsets = lngKt
Set ws = Nothing
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top