Function fctnDCount(Expr As String, Domain As String, Optional Criteria As String) As Long
On Error GoTo Err_fctnDCount
Dim rst As DAO.Recordset
If Len(Criteria) > 0 Then
Set rst = DBEngine(0)(0).OpenRecordset("SELECT COUNT(" & Expr & ") AS Counter FROM " & Domain & " WHERE " & Criteria & ";")
Else
Set rst = DBEngine(0)(0).OpenRecordset("SELECT COUNT(" & Expr & ") AS Counter FROM " & Domain & ";")
End If
rst.MoveFirst
fctnDCount = rst!Counter
rst.Close
Exit_fctnDCount:
Exit Function
Err_fctnDCount:
MsgBox Err.Number & ": " & Err.Description, vbExclamation
Resume Exit_fctnDCount
End Function
Function fctnDLookup(Expr As String, Domain As String, Optional Criteria As String) As Variant
On Error GoTo Err_fctnDLookup
Dim rst As DAO.Recordset
If Len(Criteria) > 0 Then
Set rst = DBEngine(0)(0).OpenRecordset("SELECT " & Expr & " AS Lookup FROM " & Domain & " WHERE " & Criteria & ";")
Else
Set rst = DBEngine(0)(0).OpenRecordset("SELECT " & Expr & " AS Lookup FROM " & Domain & ";")
End If
If Not rst.EOF Then
rst.MoveFirst
fctnDLookup = rst!Lookup
Else
fctnDLookup = Null
End If
rst.Close
Exit_fctnDLookup:
Exit Function
Err_fctnDLookup:
MsgBox Err.Number & ": " & Err.Description, vbExclamation
Resume Exit_fctnDLookup
End Function