Recordset Objects


This code snippet will close all Recordset objects passed to it.

'@rs - Variant object Array
'   - 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)
        End If
    Next i
On Error GoTo 0
    Exit Function
    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



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
    'Table does not exist or, by some crazy situation, there are multiple definitions
        TableExists = False
    End If
End Function




Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.