Subform recordset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings,

I have a form with a subform. The subform has custom navigation buttons,
i.e., "Previous Record", "Next Record", etc. I am using the subform's
onCurrent event property to enable/disable the navigation buttons with the
Recordsetclone property depending on the current record. Such as:
cmdPrevRec.Enabled = Me.CurrentRecord > 1

Here's the gotcha - the subform is not populated with data until the user
selects a value from a combo box on the main form. The subform's recordset
clone, therefore, has no data when the user opens the main form, triggering
an error in the code to enable/disable the subform's navigation buttons (Run
Time Error: '3021', to be exact). How can I trap or prevent this error from
occuring?

Any help will definitely be appreciated.

jn
 
Post the code that you're using for your navigation buttons. That should
allow us the chance to see where error handling is best added.
 
Ken,

Thanks for looking at this. Here's the code:

Private Sub Form_Current()

With Me.RecordsetClone
.MoveLast
cmdNextRecord.Enabled = Me.CurrentRecord < .RecordCount + 1
cmdPreviousRecord.Enabled = Me.CurrentRecord > 1
cmdFirstRecord.Enabled = Me.CurrentRecord > 1
cmdLastRecord.Enabled = Me.CurrentRecord < .RecordCount + 1
End With
End Sub
 
Try this code:
Dim Rst As DAO.Recordset
Set Rst = Me.RecordsetClone
cmdPrevRec.Enabled = Not Rst.BOF
 
PC Datasheet,

Thanks for the input. Unfortunately, I'm unable to get this to work. Is it
possible that's because I am working with a subform inside a main form with
similar code? In other words, can I use "Me.RecordsetClone" in both the main
form and subform simultaneously?

jn
 
To answer your last sentence, Yes!

Try changing to this:
Dim Rst As DAO.Recordset
Set Rst = Me.RecordsetClone
If Rst.Recordcount = 0 Then
cmdPrevRec.Enabled = False
Else
cmdPrevRec.Enabled = Not Rst.BOF
End If

Steve
PC Datasheet
 
Try this:

With Me.RecordsetClone
If .RecordCount <> 0 Then
.MoveLast
cmdNextRecord.Enabled = Me.CurrentRecord < .RecordCount + 1
cmdPreviousRecord.Enabled = Me.CurrentRecord > 1
cmdFirstRecord.Enabled = Me.CurrentRecord > 1
cmdLastRecord.Enabled = Me.CurrentRecord < .RecordCount + 1
End If
End With
End Sub
 
Back
Top