Dreamweaver
Well-known member
- Local time
- Today, 07:26
- Joined
- Nov 28, 2005
- Messages
- 2,466
I'm creating my own version of nothwind like I have been doing with my templates except I will be using my version to cover problems I see in that area of design.
I'm currently going over the old and current version of northwind to create a schema, ERD and looking for useful items and came across the module below I haven't got the tools to test it for speed etc, Although it looks very useful to me what I know is limited so thought I would ask to see if anybody can see enything that might need correcting or improving or give me there thoughts on weather it's worth using within my example.
thanks mick
I'm currently going over the old and current version of northwind to create a schema, ERD and looking for useful items and came across the module below I haven't got the tools to test it for speed etc, Although it looks very useful to me what I know is limited so thought I would ask to see if anybody can see enything that might need correcting or improving or give me there thoughts on weather it's worth using within my example.
thanks mick
Rich (BB code):
Option Compare Database
Option Explicit
Private Enum DomainFunctionWrapperEnum
DLookup_Wrapper
DCount_Wrapper
DSum_Wrapper
DMax_Wrapper
DMin_Wrapper
DAvg_Wrapper
End Enum
Private Function DomainFunctionWrapper(DomainFunction As DomainFunctionWrapperEnum, _
Expr As String, _
Domain As String, _
Optional Criteria As String) As Variant
On Error GoTo ErrorHandler
Select Case DomainFunction
Case DLookup_Wrapper
DomainFunctionWrapper = DLookup(Expr, Domain, Criteria)
Case DCount_Wrapper
DomainFunctionWrapper = DCount(Expr, Domain, Criteria)
Case DSum_Wrapper
DomainFunctionWrapper = DSum(Expr, Domain, Criteria)
Case DMax_Wrapper
DomainFunctionWrapper = DMax(Expr, Domain, Criteria)
Case DMin_Wrapper
DomainFunctionWrapper = DMin(Expr, Domain, Criteria)
Case DSum_Wrapper
DomainFunctionWrapper = DSum(Expr, Domain, Criteria)
Case DAvg_Wrapper
DomainFunctionWrapper = DAvg(Expr, Domain, Criteria)
Case Else
' Unexpected DomainFunction argument
Debug.Assert False
End Select
Done:
Exit Function
ErrorHandler:
Debug.Print Err.Number & " - " & Err.Description
' Resume statement will be hit when debugging
If eh.LogError("DomainFunctionWrapper", _
"DomainFunction = " & DomainFunction, _
"Expr = " & Expr, _
"Domain = " & Domain, _
"Criteria = '" & Criteria & "'") Then Resume
End Function
'--------------------------------------------------------
' DLookupWrapper is just like DLookup only it will trap errors.
'--------------------------------------------------------
Public Function DLookupWrapper(Expr As String, Domain As String, Optional Criteria As String) As Variant
DLookupWrapper = DomainFunctionWrapper(DLookup_Wrapper, Expr, Domain, Criteria)
End Function
'--------------------------------------------------------
' DLookupStringWrapper is just like DLookup wrapped in an Nz
' This will always return a String.
'--------------------------------------------------------
Public Function DLookupStringWrapper(Expr As String, Domain As String, Optional Criteria As String, Optional ValueIfNull As String = "") As String
DLookupStringWrapper = Nz(DLookupWrapper(Expr, Domain, Criteria), ValueIfNull)
End Function
'--------------------------------------------------------
' DLookupNumberWrapper is just like DLookup wrapped in
' an Nz that defaults to 0.
'--------------------------------------------------------
Public Function DLookupNumberWrapper(Expr As String, Domain As String, Optional Criteria As String, Optional ValueIfNull = 0) As Variant
DLookupNumberWrapper = Nz(DLookupWrapper(Expr, Domain, Criteria), ValueIfNull)
End Function
'--------------------------------------------------------
' DCountWrapper is just like DCount only it will trap errors.
'--------------------------------------------------------
Public Function DCountWrapper(Expr As String, Domain As String, Optional Criteria As String) As Long
DCountWrapper = DomainFunctionWrapper(DCount_Wrapper, Expr, Domain, Criteria)
End Function
'--------------------------------------------------------
' DMaxWrapper is just like DMax only it will trap errors.
'--------------------------------------------------------
Public Function DMaxWrapper(Expr As String, Domain As String, Optional Criteria As String) As Long
DMaxWrapper = DomainFunctionWrapper(DMax_Wrapper, Expr, Domain, Criteria)
End Function
'--------------------------------------------------------
' DMinWrapper is just like DMin only it will trap errors.
'--------------------------------------------------------
Public Function DMinWrapper(Expr As String, Domain As String, Optional Criteria As String) As Long
DMinWrapper = DomainFunctionWrapper(DMin_Wrapper, Expr, Domain, Criteria)
End Function
'--------------------------------------------------------
' DSumWrapper is just like DSum only it will trap errors.
'--------------------------------------------------------
Public Function DSumWrapper(Expr As String, Domain As String, Optional Criteria As String) As Long
DSumWrapper = DomainFunctionWrapper(DSum_Wrapper, Expr, Domain, Criteria)
End Function
'--------------------------------------------------------
' DAvgWrapper is just like DAvg only it will trap errors.
'--------------------------------------------------------
Public Function DAvgWrapper(Expr As String, Domain As String, Optional Criteria As String) As Long
DAvgWrapper = DomainFunctionWrapper(DAvg_Wrapper, Expr, Domain, Criteria)
End Function