Recordset Objects
Close
- This code snippet will close all Recordset objects passed to it.
'@rs - Variant object Array
'Notes:
' - Iterates through the Array of Objects, to represent Recordsets
Public Function RecordsetClose(ParamArray rs() As Variant) As Boolean
Dim i As Long, rst As DAO.Recordset, ret As Boolean
ret = True
On Error GoTo Err_RecordsetClose
For i = LBound(rs) To UBound(rs)
If TypeName(rs(i)) = "Recordset" Or _
TypeName(rs(i)) = "Recordset2" Then
Set rst = rs(i)
rst.Close
End If
Next i
Exit_RecordsetClose:
On Error GoTo 0
Exit Function
Err_RecordsetClose:
If Err.Number <> 0 Then
RaiseAlert "Recordset was unable to close!" & vbCrLf & vbCrLf & _
"Recordset: " & rst.Name & vbCrLf & _
"Connection: " & rst.Connection.Name & vbCrLf & _
"Error: " & Err.Number & " - " & vbCrLf & _
" - " & Err.Description & vbCrLf & vbCrLf & _
"Please advise your IT Support for assistance"
ret = False
End If
Resume Next
End Function
Tables
Exists
- This code will verify that a table name is available or not. Useful when you want to create an ad-hoc table for cache storage of information
'@tbl - String value, Name of the table to check for.
Public Function TableExists(tbl As String) As Boolean
If (DCount("[Name]", "MSysObjects", "[Name] = '" & tbl & "'") = 1) Then
'Table exists and is the only one present
TableExists = True
Else
'Table does not exist or, by some crazy situation, there are multiple definitions
TableExists = False
End If
End Function