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

No Data Query

Status
Not open for further replies.

Quan9r

Technical User
May 18, 2000
36
US
I'm in a form with a button click to another form based on a qurey.
If there is no data in the query/form I would like a messge box to pop up. I have seen the code for a report but I cannot use that same code in a form. Can someone help?

I have tried this: No luck
Private Form_NoData(Cancel As Integer)
MsgBox "There is no data for this report"
Cancel = True
End Sub
 
To do it when the button is clicked, without opening the form:
Code:
Private Sub Command1_Click()
    If DCount("*", "[red]query name[/red]") = 0 Then
        MsgBox "There are no records to display"
    Else
        DoCmd.OpenForm ...
    End If
End Sub

To do it after opening the blank form (and closing it after the message is displayed):
Code:
Private Sub Form_Open(Cancel As Integer)
    If Me.Recordset.RecordCount = 0 Then
        MsgBox "There are no records to display"
        Cancel = True
        Exit Sub
    End If

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top