Code Needed in "If" Statement

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?
 
K

Ken Hudson

Sorry, false alarm.
I did some digging and found that the correct syntax is "RecordCount" not
"Count."
 
P

Petr Danes

The correct property to use with a Recordset object is RecordCount, not
Count.

Petr
 
M

Marshall Barton

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.
 

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