L
Lynniebud
I've written the code below to calculate a field called fulldayhours, but
when I try to show this field in a query design it doesn't work. This could
either be because the code is wrong, because you can't do this in access or
because I'm referring to it incorrectly in the query! I'm not a programmer,
so don't judge the code too harshly if it's doing completely the wrong
thing...
Function fulldayhours() As Integer
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim days As Integer
Dim i As Integer
Dim n As Integer
Dim n1 As Integer
Set rst = CurrentDb.OpenRecordset("tblData_Capture2")
While Not rst.EOF
' Calculate how many full days are between the two dates
If (IsNull(rst.Fields("Date_Keyed")) Or
IsNull(rst.Fields("Application_Date"))) Then
GoTo skiprecord
Else
days = (rst!Date_Keyed - rst!Application_Date) - 1
End If
' If there are 1 or more days between the dates then identify how many hours
that constitutes
If days > 0 Then
For i = 1 To days
If WeekDay(rst!Date_Keyed - i, vbMonday) < 6 Then
n = 12
ElseIf WeekDay(rst!Date_Keyed - i, vbMonday) = 6 Then
n = 9
ElseIf WeekDay(rst!Date_Keyed - i, vbMonday) = 7 Then
n = 8
End If
n1 = n + n1
Next i
rst.MoveNext
Else
n1 = 0
rst.MoveNext
End If
skiprecord:
rst.MoveNext
fulldayhours = n1
Wend
End Function
when I try to show this field in a query design it doesn't work. This could
either be because the code is wrong, because you can't do this in access or
because I'm referring to it incorrectly in the query! I'm not a programmer,
so don't judge the code too harshly if it's doing completely the wrong
thing...
Function fulldayhours() As Integer
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim days As Integer
Dim i As Integer
Dim n As Integer
Dim n1 As Integer
Set rst = CurrentDb.OpenRecordset("tblData_Capture2")
While Not rst.EOF
' Calculate how many full days are between the two dates
If (IsNull(rst.Fields("Date_Keyed")) Or
IsNull(rst.Fields("Application_Date"))) Then
GoTo skiprecord
Else
days = (rst!Date_Keyed - rst!Application_Date) - 1
End If
' If there are 1 or more days between the dates then identify how many hours
that constitutes
If days > 0 Then
For i = 1 To days
If WeekDay(rst!Date_Keyed - i, vbMonday) < 6 Then
n = 12
ElseIf WeekDay(rst!Date_Keyed - i, vbMonday) = 6 Then
n = 9
ElseIf WeekDay(rst!Date_Keyed - i, vbMonday) = 7 Then
n = 8
End If
n1 = n + n1
Next i
rst.MoveNext
Else
n1 = 0
rst.MoveNext
End If
skiprecord:
rst.MoveNext
fulldayhours = n1
Wend
End Function