S
Seikyo
How come I can use this function in SQL Queries? It said that my function is
not defined. Sighx... Can anyone check if there is any problem with it? I
modified from some source code to suit my project.
Public Function OverTime(dteSCHD As Date, dteEnd As Date, dteBase As Date,
dteLate As Date, Optional vSeparator As Variant = ":") As Variant
Dim iHr As Integer
Dim iHrTemp As Integer
Dim iMin As Integer
Dim iMinTemp As Integer
Dim dteTemp As Date
Dim vTemp As Variant
Dim bSwapped As Boolean
OverTime = Null
bSwapped = False
'Check that both dates are valid
If Not IsDate(dteSCHD) Or Not IsDate(dteEnd) Or Not IsDate(dteBase) Then
DoCmd.Beep
MsgBox "You must supply valid dates.", vbOKOnly + vbExclamation,
"Invalid date"
Exit Function
End If
'Check that dteStart < dteEnd
If dteSCHD > dteEnd Then
'dteStart > dteEnd. Swap them
dteTemp = dteSCHD
dteSCHD = dteEnd
dteEnd = dteTemp
bSwapped = True
End If
'Calculate the time differences
iHr = DateDiff("h", dteSCHD, dteEnd) - _
IIf(Format(dteSCHD, "nnss") <= Format(dteEnd, "nnss"), 0, 1)
dteSCHD = DateAdd("h", iHr, dteSCHD)
iMin = DateDiff("n", dteSCHD, dteEnd) - _
IIf(Format(dteSCHD, "ss") <= Format(dteEnd, "ss"), 0, 1)
dteSCHD = DateAdd("n", iMin, dteSCHD)
If iHr >= 6 Then
iHr = DateDiff("h", 1, iHr) ' Lunch Hour (Standard 1 Hour)
iHrTemp = DateDiff("h", dteBase, iHr) - _
IIf(Format(dteBase, "nnss") <= Format(iHr, "nnss"), 0, 1) 'Calculate
the time differences
dteBase = DateAdd("h", iHrTemp, dteBase)
iHr = iHrTemp
If (iHr = 0) And (iMin < 10) Then
iHr = 0
iMin = 0
ElseIf (iHr < 0) Then
dteLate = DateAdd("h", Abs(iHr), dteLate)
dteLate = DateAdd("n", Abs(iMin), dteLate)
End If
Else
iHr = DateDiff("h", dteBase, iHr) - _
IIf(Format(dteBase, "nnss") <= Format(iHr, "nnss"), 0, 1) 'Calculate
the time differences
dteBase = DateAdd("h", iHr, dteBase)
If (iHr = 0) And (iMin < 10) Then
iHr = 0
iMin = 0
ElseIf (iHr < 0) Then
dteLate = DateAdd("h", Abs(iHr), dteLate)
dteLate = DateAdd("n", Abs(iMin), dteLate)
End If
End If
vTemp = iHr & vSeparator & iMin
OverTime = IIf(bSwapped, "-", "") & vTemp
'Debug.Print iHrs & ":" & iMin
End Function
not defined. Sighx... Can anyone check if there is any problem with it? I
modified from some source code to suit my project.
Public Function OverTime(dteSCHD As Date, dteEnd As Date, dteBase As Date,
dteLate As Date, Optional vSeparator As Variant = ":") As Variant
Dim iHr As Integer
Dim iHrTemp As Integer
Dim iMin As Integer
Dim iMinTemp As Integer
Dim dteTemp As Date
Dim vTemp As Variant
Dim bSwapped As Boolean
OverTime = Null
bSwapped = False
'Check that both dates are valid
If Not IsDate(dteSCHD) Or Not IsDate(dteEnd) Or Not IsDate(dteBase) Then
DoCmd.Beep
MsgBox "You must supply valid dates.", vbOKOnly + vbExclamation,
"Invalid date"
Exit Function
End If
'Check that dteStart < dteEnd
If dteSCHD > dteEnd Then
'dteStart > dteEnd. Swap them
dteTemp = dteSCHD
dteSCHD = dteEnd
dteEnd = dteTemp
bSwapped = True
End If
'Calculate the time differences
iHr = DateDiff("h", dteSCHD, dteEnd) - _
IIf(Format(dteSCHD, "nnss") <= Format(dteEnd, "nnss"), 0, 1)
dteSCHD = DateAdd("h", iHr, dteSCHD)
iMin = DateDiff("n", dteSCHD, dteEnd) - _
IIf(Format(dteSCHD, "ss") <= Format(dteEnd, "ss"), 0, 1)
dteSCHD = DateAdd("n", iMin, dteSCHD)
If iHr >= 6 Then
iHr = DateDiff("h", 1, iHr) ' Lunch Hour (Standard 1 Hour)
iHrTemp = DateDiff("h", dteBase, iHr) - _
IIf(Format(dteBase, "nnss") <= Format(iHr, "nnss"), 0, 1) 'Calculate
the time differences
dteBase = DateAdd("h", iHrTemp, dteBase)
iHr = iHrTemp
If (iHr = 0) And (iMin < 10) Then
iHr = 0
iMin = 0
ElseIf (iHr < 0) Then
dteLate = DateAdd("h", Abs(iHr), dteLate)
dteLate = DateAdd("n", Abs(iMin), dteLate)
End If
Else
iHr = DateDiff("h", dteBase, iHr) - _
IIf(Format(dteBase, "nnss") <= Format(iHr, "nnss"), 0, 1) 'Calculate
the time differences
dteBase = DateAdd("h", iHr, dteBase)
If (iHr = 0) And (iMin < 10) Then
iHr = 0
iMin = 0
ElseIf (iHr < 0) Then
dteLate = DateAdd("h", Abs(iHr), dteLate)
dteLate = DateAdd("n", Abs(iMin), dteLate)
End If
End If
vTemp = iHr & vSeparator & iMin
OverTime = IIf(bSwapped, "-", "") & vTemp
'Debug.Print iHrs & ":" & iMin
End Function