By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,158 Members | 917 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,158 IT Pros & Developers. It's quick & easy.

how to check if result query is 0 records

P: n/a
I want to open a form that is based on a query. When the output of the
query results in 0 records, I don't want to open the form but just
display a messagebox. Is there a way to check if the result of the
query = 0 records??
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Run some code in the form's Open event (air code, not tested):

Dim db As Database, rs As Recordset, strSQL As String
Set db = CurrentDb
strSQL = "Select * From MyQuery"
Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount = 0 Then DoCmd.Close acForm, Me.Name
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

"MyQuery" is the name of the query the form is based upon.
HTH - Keith.
www.keithwilby.org.uk

"A.J.M. van Rijthoven" <to***@xs4all.nl> wrote in message
news:4s********************************@4ax.com...
I want to open a form that is based on a query. When the output of the
query results in 0 records, I don't want to open the form but just
display a messagebox. Is there a way to check if the result of the
query = 0 records??

Nov 12 '05 #2

P: n/a
A.J.M. van Rijthoven wrote:
I want to open a form that is based on a query. When the output of the
query results in 0 records, I don't want to open the form but just
display a messagebox. Is there a way to check if the result of the
query = 0 records??


(air code)
Sub Form_Open(Cancel As Integer)
if Me.RecordsetClone.Recordcount=0 then
msgbox "sorry m8, nothing 'ere for yer"
Cancel = True
end if
End Sub

--
Error reading sig - A)bort R)etry I)nfluence with large hammer
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.