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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop a form with no data from opening 1

Status
Not open for further replies.

RandyMyers

IS-IT--Management
Apr 28, 2004
85
US
I have a search form where criteria can be entered and when ok is clicked a continuous form opens displaying all records that match the entered criteria. The user can then drill down on this form to get details on the specific record that they need.

If no records match the criteria I want to display a message and prevent the form from opening with no records.

BTW the criteria are passed from the search form to open the continuous display form through criteria being passed from the search form to the query behind the continuous form.

Any idea of how to prevent a form form opening if there are no records behind it?
 
Before opening the form, open a recordset (or use one of the Domain Aggregates) with the same criteria, and check if you it contains any records. If not, give a message and skip the opening.

Roy-Vidar
 
In the Open event


Private Sub Form_Open(Cancel As Integer)

Dim rst As Recordset

On Error Resume Next

Set rst = Me.RecordsetClone

rst.MoveLast
If rst.RecordCount = 0 Then
MsgBox "No records. Form will not display"
Cancel = True
End If

End Sub
 
Ok Craig,

This worked... of course with a little modification. Thank you so much for your help...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top