473,574 Members | 3,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for Query Results with no Records

I have the following code:

Private Sub cmdDatasheet_Cl ick()
DoCmd.OpenQuery "qryCourse_Deta ils"
End Sub

I would like to check to make sure that this above query has zero rows,
then show a message box that says "There are no results in your query".

I can not put the following code in the forms open event but that
doesn't help as the query result is in a datasheet, not a form.

If Me.RecordsetClo ne.RecordCount = 0 Then
MsgBox "Your request returned no records."
Cancel = True
End If

Is there any way to check if the results from a DoCmd.OpenQuery has
zero rows or not?
Marcus
******

Nov 13 '05 #1
5 28049
"Marcus" <to*******@yaho o.ca> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .
I have the following code:

Private Sub cmdDatasheet_Cl ick()
DoCmd.OpenQuery "qryCourse_Deta ils"
End Sub

I would like to check to make sure that this above query has zero rows,
then show a message box that says "There are no results in your query".

I can not put the following code in the forms open event but that
doesn't help as the query result is in a datasheet, not a form.

If Me.RecordsetClo ne.RecordCount = 0 Then
MsgBox "Your request returned no records."
Cancel = True
End If

Is there any way to check if the results from a DoCmd.OpenQuery has
zero rows or not?
Marcus
******

Why not build a form? It would take so little time and then you can use
your suggested solution. If you feel this is too much work, then why not
simply open the query with no rows? Would the MsgBox really explain the
situation any better than a query with no rows?
If you decide you need to open the query, then you could write a function:

Public Function QueryReturnsRec ords(strQueryNa me As String) As Boolean

Where you open the query with code and check for rst.eof - does this make
sense? If the query is quick then this may be a possibility.

Nov 13 '05 #2
the normal place for this is in a report, hence the NoData event.

Nov 13 '05 #3
Marcus, I think you just need this:

Private Sub cmdDatasheet_Cl ick()
If DCount("*","qry Course_Details" ) > 0 then
DoCmd.OpenQuery "qryCourse_Deta ils"
Else
Msgbox "No records ... "
End if
End Sub

Arno R
"Marcus" <to*******@yaho o.ca> schreef in bericht news:11******** **************@ l41g2000cwc.goo glegroups.com.. .
I have the following code:

Private Sub cmdDatasheet_Cl ick()
DoCmd.OpenQuery "qryCourse_Deta ils"
End Sub

I would like to check to make sure that this above query has zero rows,
then show a message box that says "There are no results in your query".

I can not put the following code in the forms open event but that
doesn't help as the query result is in a datasheet, not a form.

If Me.RecordsetClo ne.RecordCount = 0 Then
MsgBox "Your request returned no records."
Cancel = True
End If

Is there any way to check if the results from a DoCmd.OpenQuery has
zero rows or not?


Marcus
******

Nov 13 '05 #4
Which procedure would be more efficient, or does it not really matter
which one is used?

Private Sub cmdDatasheet_Cl ick()
If Nz(Dcount("Cour seId","qryCours e_Details"), 0) = 0 then
MsgBox "No records were found."
Else
DoCmd.OpenQuery "qryCourse_Deta ils"
End If
End Sub

Or

Private Sub cmdDatasheet_Cl ick()
If Nz(DCount("Cour seId","qryCours e_Details"*), 0) > 0 then
DoCmd.OpenQuery "qryCourse_Deta ils"
Else
MsgBox "No records were found."
End if
End Sub
Marcus
*********

Nov 13 '05 #5
Marcos,
The difference (if any) between your examples does NOT matter.
You could try to speedup DCount and other domain aggregate functions by Google-searching for Domain Function Replacements
at http://www.trevor.easynet.co.uk/AccFAQ/
You can skip the Nz-part however, not needed here ...

Arno R

"Marcus" <to*******@yaho o.ca> schreef in bericht news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Which procedure would be more efficient, or does it not really matter
which one is used?

Private Sub cmdDatasheet_Cl ick()
If Nz(Dcount("Cour seId","qryCours e_Details"), 0) = 0 then
MsgBox "No records were found."
Else
DoCmd.OpenQuery "qryCourse_Deta ils"
End If
End Sub

Or

Private Sub cmdDatasheet_Cl ick()
If Nz(DCount("Cour seId","qryCours e_Details"*), 0) > 0 then
DoCmd.OpenQuery "qryCourse_Deta ils"
Else
MsgBox "No records were found."
End if
End Sub
Marcus
*********

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5562
by: Guy Erez | last post by:
Hi, I'm running queries with MySql 4.0.17 that return thousands of records. Because I need to present them in GUI, I returieve the results in chunks using LIMIT, for example - get first 100, then the range 100-2000 and so on. The problem is as follows: in the first chunk, MySQL uses one strategy to fetch the results, and in the following...
4
10423
by: M Wells | last post by:
Hi All, I have a table that currently contains approx. 8 million records. I'm running a SELECT query against this table that in some circumstances is either very quick (ie results returned in Query Analyzer almost instantaneously), or very slow (ie 30 to 40 seconds to return results), and I'm trying to work out how I improve performance....
2
460
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 of the query = 0 records??
4
3705
by: Macroman | last post by:
MS Access XP, running on Win XP, Processor 2.4Ghz , 512Mb RAM, 40Gb Hard drive Table 1 has 167,000 records and contains the following fields tblone_custID tblone_easting tblone_northing Table 2 has 423,000 records and contains the following fields tbltwo_custID
10
6210
by: sesling | last post by:
I have created a query that will pull information from our database for the operators. This query will pull in on average 50,000 records. The operators need to refine the search results. I have used the following in the criteria section of the query for the operators to refine the search . However, the operators do not always remember how the...
1
1839
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 resultsets in Gridview. For ex., in the form I am entering contract id and running the query for that contract id. If results found then use that...
7
3746
by: sesling | last post by:
Currently I am using 3 text boxes (status1, status2, status3) on a form and passing the values to a query. The operator will enter one of three statuses (Open, Closed, Pending) in one or more text boxes. The operator will execute a query and the results will be returned based on what they enter. Below I have listed the criteria statement from...
1
11501
by: Euge | last post by:
Hi, I really hope someone will be able to help me with this one as I am sure im just missing something simple. I have an unbound form which has 20 yes/no unbound check boxes. The purpose of the form is to allow users to tick the various fields and a subform return the results. The subform, which does requery when a check box is ticked is...
5
3819
by: slickdock | last post by:
I need to break my query into 3 groups: First 60 records (records 1-60) Next 60 records (records 61-121) Next 60 records (records 122-182) Of course I could use top values 60 for the first query, but where do I go from there?
0
8111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7863
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8140
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6514
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5336
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1375
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.