Function
fcDomWert(Expression
As
String
, Domain
As
String
, _
Optional
Criteria
As
String
, _
Optional
ltDomArt
As
ltDomWert = ltDLookup)
As
Variant
Dim
strSQL
As
String
Dim
rs
As
DAO.Recordset
Select
Case
ltDomArt
Case
0: strSQL$ =
"SELECT "
& Expression$ &
" FROM "
& Domain$
Case
1: strSQL$ =
"SELECT COUNT(*) FROM "
& Domain$
Case
2: strSQL$ =
"SELECT MAX("
& Expression$ &
") FROM "
& Domain$
Case
3: strSQL$ =
"SELECT MIN("
& Expression$ &
") FROM "
& Domain$
Case
4: strSQL$ =
"SELECT FIRST("
& Expression$ &
") FROM "
& Domain$
Case
5: strSQL$ =
"SELECT LAST("
& Expression$ &
") FROM "
& Domain$
Case
6: strSQL$ =
"SELECT SUM("
& Expression$ &
") FROM "
& Domain$
Case
7: strSQL$ =
"SELECT AVG("
& Expression$ &
") FROM "
& Domain$
End
Select
If
Nz(Criteria$,
""
) <>
""
Then
strSQL$ = strSQL$ &
" WHERE "
& Criteria$
Set
rs = CurrentDb.OpenRecordset(strSQL$, dbOpenForwardOnly)
If
rs.EOF
Then
fcDomWert = Null
Else
fcDomWert = rs.Fields(0)
End
If
rs.Close
Set
rs =
Nothing
End
Function