Code Needed in "If" Statement

  • Thread starter Thread starter Ken Hudson
  • Start date Start date
K

Ken Hudson

I have the following event code:

Private Sub cboProjects_Change()
frmPOsub.Requery
frmPOsub.Form.Recordset.MoveFirst
End Sub

If the frmPOsub has no records, I get an error message. I am trying to use
an "If" statement to bypass that error, but don't know the correct syntax.
The following does not work.

Private Sub cboProjects_Change()
frmPOsub.Requery
If frmPOsub.Form.Recordset.Count > 0 Then
frmPOsub.Form.Recordset.MoveFirst
End If
End Sub

Can someone please assist?
 
Sorry, false alarm.
I did some digging and found that the correct syntax is "RecordCount" not
"Count."
 
The correct property to use with a Recordset object is RecordCount, not
Count.

Petr
 
Ken said:
The following does not work.

Private Sub cboProjects_Change()
frmPOsub.Requery
If frmPOsub.Form.Recordset.Count > 0 Then
frmPOsub.Form.Recordset.MoveFirst
End If
End Sub


You need to use the RecordCount property. Then it should be
ok if the combo box is on the main form and frmPOsub is a
subform control on the main form.

Note that you probably should move the code out of the
Change event and into the AfterUpdate event.
 
Back
Top