Hi,
i have a recordset in a function that is called on the afterupdate event in a form
Basically the recordset finds the relevant session records and adds up how long, in hours, the sessions took and wites the sum of the session times into a seperate table this all works fine when i add a record, more time is added and when i delete a record time is taken away but when i delete the last record the error message "invalid use of null" appears this is because the record that i am refering to in the recordset has been deleted before the code for the recordset has run i have tried running the function on the after del confirm, on delete, and before del confirm event but with no luck
Any help is greatly appreciated
Regards Phill
i have a recordset in a function that is called on the afterupdate event in a form
Basically the recordset finds the relevant session records and adds up how long, in hours, the sessions took and wites the sum of the session times into a seperate table this all works fine when i add a record, more time is added and when i delete a record time is taken away but when i delete the last record the error message "invalid use of null" appears this is because the record that i am refering to in the recordset has been deleted before the code for the recordset has run i have tried running the function on the after del confirm, on delete, and before del confirm event but with no luck
Any help is greatly appreciated
Regards Phill
Code:
Dim dbsCurrent As Database
Dim dbsLinkedData As Database
Dim rstQAssignedHrsSum As dao.Recordset
Dim rstTblAssignHrs As dao.Recordset
Dim strSeekProjID As String
Dim strSeekSessionID As String
Dim nullvalue As Variant
Dim rstExpr1 As String
Dim SumOfHrs As Integer
Dim HrsStore As Integer
Dim HrsTotal As Integer
Dim rstProjID As Integer
Dim rstSessTypeID As Integer
Dim rstCompletedHrs As Variant
Dim varbookmark As Variant
'sets quer recordset and the the table where the data is going to be written
Set dbsCurrent = CurrentDb
Set dbsLinkedData = DBEngine.OpenDatabase("C:\Database\ClientBooking\ExampleAccess2000")
Set rstTblAssignHrs = _
dbsLinkedData.OpenRecordset("T_AssignHours", dbOpenTable)
Set rstQAssignedHrsSum = _
dbsCurrent.OpenRecordset("Q_SFormTotalHrs1", dbOpenDynaset)
strSeekProjID = Forms![F_ClientDetails]![SF_Session].Form![ProjID]
strSeekSessionID = Forms![F_ClientDetails]![SF_Session].Form![SessTypeID]
'sets data to be searched
'loops query and adds up the total completed hours
With rstQAssignedHrsSum
Do
Do Until rstQAssignedHrsSum.EOF
rstExpr1 = rstQAssignedHrsSum!expr1
HrsStore = HrsStore + rstExpr1
.MoveNext
HrsTotal = HrsTotal + HrsStore
HrsStore = 0
Loop
Loop Until rstQAssignedHrsSum.EOF
.Close
End With
'loops table until record is found and writes data to field
With rstTblAssignHrs
Do
Do Until rstTblAssignHrs.EOF
rstProjID = rstTblAssignHrs!ProjectID
rstSessTypeID = rstTblAssignHrs!SessTypeID
If rstProjID = strSeekProjID And rstSessTypeID = strSeekSessionID Then
rstTblAssignHrs.Edit
rstTblAssignHrs!completedhrs = HrsTotal
rstTblAssignHrs.Update
End If
.MoveNext
Loop
Loop Until rstTblAssignHrs.EOF
.Close
End With
'Exit_Command16_Click:
Exit Function
'Err_Command16_Click:
' MsgBox Err.Description
' Resume Exit_Command16_Click
Exit Function
End Function
Comment