I was working on some error trapping code which I would like to use to handle any type of error, and clean up where need be IF necessary. The part I am wanting to verify is how to check for open recordsets (DAO preferable), and close them if open, and set to nothing if they exist.
So, here is some psuedo code demonstrating what I would like to do:
Or if were possible to do something like this:
If anyone has any critiques or suggestions at all on this, I would greatly appreciate any input given.
Thanks!
So, here is some psuedo code demonstrating what I would like to do:
Code:
Private Sub CreateSomeRecordsets()
On Error GoTo HandleErr
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim rs3 As DAO.Recordset
Set db = CurrentDb
Set rs1 = db.OpenRecordset("Table1")
Set rs2 = db.OpenRecordset("Table2")
Set rs3 = db.OpenRecordset("Table3")
'Code to do what I want to do with the 3 tables
Exit Sub
HandleErr:
MsgBox Err.Code & " " & Err.Description
If Exists(rs1) Then
If IsOpen(rs1) Then
rs1.Close
End If
Set rs1 = Nothing
End If
If Exists(rs2) Then
If IsOpen(rs2) Then
rs2.Close
End If
Set rs2 = Nothing
End If
If Exists(rs3) Then
If IsOpen(rs3) Then
rs3.Close
End If
Set rs3 = Nothing
End If
If Exists(db) Then
If IsOpen(db) Then
db.Close
End If
Set db = Nothing
End If
Or if were possible to do something like this:
Code:
For Each rs in db.Recordsets
'Check to see if exists, and if open, close/clear as necessary.
Next rs
If anyone has any critiques or suggestions at all on this, I would greatly appreciate any input given.
Thanks!