The "No Current Record" Mystery (1 Viewer)

Jurjen

Registered User.
Local time
Today, 22:36
Joined
Oct 26, 2007
Messages
27
I have a main form containing PERSON records (frm_pers). Within it there is a subform containing their TELEPHONE numbers (frm_tele). The forms are based on the tables PERS and TELE. The primary key field of PERS is named pers_id and so is the foreign key field of TELE. So the "link child fields" and "link master fields" properties of the subform are both "pers_id". This is all very simple.
In the subform frm_tele i have two arrow buttons to move records up and down. To enable/disable these buttons i wrote the following code in the "On Current" trigger:

but_up.Enabled = CurrentRecord > 1
but_dn.Enabled = CurrentRecord < Recordset.RecordCount

The idea is simple: the first record cannot be moved up and the last record cannot be moved down. It works perfect.

But now comes the trouble: if i close the main form and the subform contains no records then this code leads to the error message "No Current Record".
If i remove the 2 lines the error does not occur. What makes it really indigestible is that the "On Current" event does not fire at all, when there are no records (i put a message box to verify this)! Still the code within it leads to an error ...
Is there anybody who understands this?
 
Last edited:

RuralGuy

AWF VIP
Local time
Today, 15:36
Joined
Jul 2, 2005
Messages
13,826
Try the following code:
Code:
Private Sub Form_Current()
   If Me.Recordset.RecordCount <> 0 Then
      '-- RecordCount is not guaranteed accurate until after a .MoveLast
      Me.RecordsetClone.MoveLast
      Me.but_up.Enabled = CurrentRecord > 1
      Me.but_dn.Enabled = CurrentRecord < RecordsetClone.RecordCount
   End If
End Sub
 

Jurjen

Registered User.
Local time
Today, 22:36
Joined
Oct 26, 2007
Messages
27
"No Current Record Mystery" solved!

Dear Rural Guy,

thank you for your answer: although initially the error message was still there, your suggestion of using RecordsetClone instead of Recordset helped me to solve the mystery! The "On Current" trigger now has the following code

Code:
If RecordsetClone.RecordCount = 0 Then
    but_up.Enabled = False
    but_dn.Enabled = False
Else
    RecordsetClone.MoveLast
    but_up.Enabled = CurrentRecord > 1
    but_dn.Enabled = CurrentRecord < RecordsetClone.RecordCount
End If

The IF-statement in your solution still contained a reference to Recordset.RecordCount, which caused the error message to appear (and NOT the reference to CurrentRecord).
Thank you so much! I am very happy that it works now.
 

RuralGuy

AWF VIP
Local time
Today, 15:36
Joined
Jul 2, 2005
Messages
13,826
I'm pretty sure that an empty RecordSet should not throw and error if you access the RecordCount property. That is a generally accepted method of determining if the RecordSet has any records.
 

Jurjen

Registered User.
Local time
Today, 22:36
Joined
Oct 26, 2007
Messages
27
>> I'm pretty sure that an empty RecordSet should not throw and error if you access the RecordCount property. That is a generally accepted method of determining if the RecordSet has any records.

Well, still this is what made the difference: with RecordSet.RecordCount the error message appears, with RecordsetClone.RecordCount it does not.
Note that the error only appears when i close the main form (frm_pers), not when i select a person without telephone numbers. There seems to be a strange side effect when the "On Current" event of the subform is caused by indirectly closing it. Changing the master record in the main form, also causes the "On Current" event, but
in that case no error occurs.
Again thank you very much: the problem is solved now.
 

Users who are viewing this thread

Top Bottom