S
Savvoulidis Iordanis
I use the following function to get the recordcount of a form/subform.
Public Function FRMRecordCount(afrm As Form) As Long
Dim rs As DAO.Recordset
FRMRecordCount = 0
If IsNull(afrm) Or IsNull(afrm.Recordset) Then Exit Function
afrm.RecordsetClone.MoveLast
FRMRecordCount = afrm.RecordsetClone.RecordCount
End Function
At first, it seems OK, but sometimes it does not work correctly.
When I call SQL commands that alter (add/delete) the underlying contents of
the form/subform, then after doing a requery on the form/subform and then
run the above function, I get the message: '3420: Object invalid or no
longer set'
on line :
afrm.RecordsetClone.MoveLast
Doesn't the requery reload the data based on the current recordsource of the
form, and if yes, then why the function crashes?
I call the function like this:
If FRMRecordCount(f1_subform.Form) = 0 Then
...
end if
where f1_subform is a subform control on the main form.
Public Function FRMRecordCount(afrm As Form) As Long
Dim rs As DAO.Recordset
FRMRecordCount = 0
If IsNull(afrm) Or IsNull(afrm.Recordset) Then Exit Function
afrm.RecordsetClone.MoveLast
FRMRecordCount = afrm.RecordsetClone.RecordCount
End Function
At first, it seems OK, but sometimes it does not work correctly.
When I call SQL commands that alter (add/delete) the underlying contents of
the form/subform, then after doing a requery on the form/subform and then
run the above function, I get the message: '3420: Object invalid or no
longer set'
on line :
afrm.RecordsetClone.MoveLast
Doesn't the requery reload the data based on the current recordsource of the
form, and if yes, then why the function crashes?
I call the function like this:
If FRMRecordCount(f1_subform.Form) = 0 Then
...
end if
where f1_subform is a subform control on the main form.