• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

how to check if the recordset is opened or close with DAO



Hi,

I searched on this web site, and some people suggest to compare it with Nothing, but I am not quite sure about it...

Is there an attribute or something for DAO recordset...for example...state, status, or something

Thanks
0
TungVan
Asked:
TungVan
  • 2
1 Solution
 
PePiCommented:
for ADO it's .State. I am not sure for DAO though. Might be the same, try it.
0
 
PaulHewsCommented:
The only way to be really certain is to use error trapping:

Private Sub Form_Load()
    Dim db As Database
    Set db = OpenDatabase("C:\temp\test2.mdb")
   
    Dim rs As Recordset
    Set rs = db.OpenRecordset("Table1", dbOpenSnapshot)
    Do While Not rs.EOF
        Debug.Print rs(1)
    Loop
   
   
    MsgBox IsRecordsetOpen(rs)
    rs.Close
    MsgBox IsRecordsetOpen(rs)
    db.Close
   
End Sub

Private Function IsRecordsetOpen(rs As Recordset) As Boolean
    Dim bRet As Boolean
    On Error Resume Next
    If rs.BOF Then
        'do nothing
    End If
    bRet = Not (Err.Number = 3420)
    On Error GoTo 0
    IsRecordsetOpen = bRet
End Function
0
 
PaulHewsCommented:
Testing Is Nothing only works if the object is actually set to nothing in the code.  If someone closes the recordset without setting it to nothing, you wouldn't know if it was open or not.  You can test that yourself.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now