Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset of my form...

Status
Not open for further replies.

griswom

Technical User
May 13, 2002
40
US
Hello all,

I have a form that uses a parameter query to build the recordset for the form. After the parameter is entered, I would like to be able to test to see if the query returns any records. If so...load form, if not...close form. How can this be accomplished? Any advice would be appreciated. Thanks,

Griz
 
Try this as the form's On Load event...


Private Sub Form_Load()

If Me.RecordsetClone.RecordCount = 0 Then

MsgBox "No records to display.", vbInformation
DoCmd.Close acForm, "YourFormNameHere"

End If

End Sub

Hope this helps...

prodevmg@yahoo.com
ProDev, MS Access Applications B-)
May God bless you in the year 2002.
 
You can use the RecordCount property of a recordset to see if any records were returned. If the name of your recordset is rs, this would work:

If rs.RecordCount > 0
DoCmd.OpenForm...
Else
DoCmd.Close
End If

dz
 
You can use the form's recordsetclone. With an IF statment...
Code:
If Me.RecordSetClone.RecordCount = 0 Then
     DoCmd.Close acForm, Me.Name
End If
Just paste this into the Form's OnOpen event.
God Bless
Mike ;-)
 
Apparently we must have all been typing at the same time. LOL God Bless
Mike ;-)
 
Yes, Mike. lol I hate when that happens because somebody might think that you are infringing on their territory! :eek:)

Best,

dz
 
Hello All,

Thank you for all of the quick and accurate responses. I implemented this into my form and it works beautifully. I appreciate your time and efforts.

Griz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top