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

How do i verify if a table contains any data? 1

Status
Not open for further replies.

bigdars

MIS
Dec 13, 2001
29
US
I have a table named tblMultiple that (might) contain temporary data for a report. When the user selects a report button I had created, I want to verify if there is any data in that table prior to pulling up this report. If there is not any data, I want to give them a message that there is no data. If there is data then I want to pull up the report. Any suggestions?
 
On the click event of the button do this.

************************************************
Dim db As Database
Dim rsCheck As Recordset

Set db = CurrentDb
Set rsCheck = db.OpenRecordset("tblMultiple")

With rsCheck
If .EOF And .BOF Then
MsgBox "No Data To Display"
Exit Sub
End If
End With

Do.Cmd ReportName, acPreview
*************************************************

If a recordset contains no data, the end of file and beginning of file Boolean values will both be TRUE. So just check for that condition and if it exists, display the message box and jump out of the subroutine.
 
Thanks a bunch!

I had to change the final do.cmd command to ...

DoCmd.OpenReport ReportName, acPreview

...for anyone else that wants to use this code. Other than that it was a copy and paste to my report button on click command.

This will save the time by determining if there is data to report prior to going to the report.

Thanks Jables![thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top