'No Current Record' error from subform on Close

D

DocBrown

I can't find an existing solution to this problem.

I have a main form that contains a subform whose record source is the
following query:

SELECT VolunteerLog.VolunteerID, nz(Sum([timeout]-[timein]),0) AS TotalHours
FROM VolunteerLog
GROUP BY VolunteerLog.VolunteerID;

The main form contains data for an individual Volunteer. The Subform
displays the total hours a volunteer has worked. The subform is linked to the
main form with the field VolunteerID. The volunteerLog is a record of the
shifts all the volunteers have worked. The subform displays the TotalHours
calculated field which is formatted into hh:mm.

The problem is this: If the main form is displaying a Volunteer who has no
logged hours and then I close the main form, I get a dialog warning box that
says 'No Current Record. I have confirmed that the error is coming from the
subform. For the OnError event in the subform, I coded the following:

MsgBox Err.Number & ":" & Err.Source & ":" & Err.Description

The msgbox displays: 0::

That's IT.

I've tried to put a normal field from the volunteerLog table in place of the
TotalHours field, but same error occurs.

Anyone have any ideas?

Thanks,
John
 
D

DocBrown

Upon further testing, I reduced the code until I have found out the following:

The error is triggered by the following code I have in the Main form for the
On Current event:

Private Sub Form_Current()
....

If Me.subfLogTotalHours.Form.Recordset.RecordCount > 0 Then
.....

Me.txtComplete = "No Commitment."
Else
Me.txtComplete = "No logged hours."
End If

.....

End Sub

So it appears that this reference to the subform that is closing causes the
error. How do I code to avoid the error?

Suggestions are very welcome.
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top