Edit: 6th post (5th reply) is simpler version of the problem
This function works in the immediate window of the VB builder. When I use it in a query it throws up an Invalid use of null error for each reccord.
The Red code is where the debugger says the error is.
In the query that generates the error there's a field called DateWorked, it's that table's index so it can't be Null.
I've created the field "MissedHours: dayMissedHours([DateWorked])". This is what calls the function and generates the error.
Non of the fields it's looking for are null, I've checked. It works in the immediate window. Why is it not working in the query??!!
This function works in the immediate window of the VB builder. When I use it in a query it throws up an Invalid use of null error for each reccord.
Code:
Public Function dayMissedHours(WorkedDay As Date)
Dim s1 As Integer
If DLookup("[NoOfStaffRequired]", "hours", "[DateWorked] = #" & WorkedDay & "#") >= 1 And Not (IsNull(DLookup("[Staff1PIN]", "hours", "[DateWorked] = #" & WorkedDay & "#"))) Then 'If staff is req AND a staff member is entered then
s1 = StaffMissedHours(DLookup("[Staff1PIN]", "hours", "[DateWorked] = #" & WorkedDay & "#"), WorkedDay) 'Work out missed hours for that staff member
Else
If DLookup("[NoOfStaffRequired]", "hours", "[DateWorked] = #" & WorkedDay & "#") < 1 Then 'Staff not required, missed hours = 0
s1 = 0
Else 'Els must be staff required but not entered
[COLOR="Red"]s1 = DLookup("[ShiftLength]", "WorkedShiftTypeLookup", "[ShiftType] =""" & _
(DLookup("[s1Type]", "hours", "[DateWorked] = #" & WorkedDay & "#")) & """" _
) [/COLOR] 'missed hours = shift length
End If
End If
dayMissedHours = s1
The Red code is where the debugger says the error is.
In the query that generates the error there's a field called DateWorked, it's that table's index so it can't be Null.
I've created the field "MissedHours: dayMissedHours([DateWorked])". This is what calls the function and generates the error.
Non of the fields it's looking for are null, I've checked. It works in the immediate window. Why is it not working in the query??!!
Last edited: