473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to check if result query is 0 records

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
2 5620
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
2
by: A.J.M. van Rijthoven | last post by:
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...
6
by: Nicolae Fieraru | last post by:
Hi All, I have a query, Select Count(BoolField) from tblMyTable, Where BoolField = true. If I run the query by itself, it returns the number of true records I want to use the result of that...
5
by: Marcus | last post by:
I have the following code: Private Sub cmdDatasheet_Click() DoCmd.OpenQuery "qryCourse_Details" End Sub I would like to check to make sure that this above query has zero rows, then show a...
3
by: Simon | last post by:
Dear reader, I found out a strange behaviour in a query of the type Total (summation query). In case of a normal select query with a criteria setting Is Null for field-A, four (4) records...
2
by: Alec | last post by:
First attempt at doing an exercise on paginating result sets When I run the code, I receive the error "Fatal error: Call to undefined function: mysql_fetch_objects() in...
2
by: 00webman | last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/scripts/07/view_users.php on line 15 Can anyone spot my error?!? Thanks. <?php # Script 7.6 -...
1
by: mamun | last post by:
Hi All, I am doing it for the first time in C# (using Visual Studio 2005), First I need to check if data exists in a table for a variable. If so then run the second query and display the...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
6
ddtpmyra
by: ddtpmyra | last post by:
Hi Guru's This is a continuation of my last post, but I decided to create a new thread for my new question. Last post click here: Problem: How to update a check box value to mysql records ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.