472,378 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Check for Query Results with no Records

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 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.RecordsetClone.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 27806
"Marcus" <to*******@yahoo.ca> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
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 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.RecordsetClone.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 QueryReturnsRecords(strQueryName 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_Click()
If DCount("*","qryCourse_Details") > 0 then
DoCmd.OpenQuery "qryCourse_Details"
Else
Msgbox "No records ... "
End if
End Sub

Arno R
"Marcus" <to*******@yahoo.ca> schreef in bericht news:11**********************@l41g2000cwc.googlegr oups.com...
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 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.RecordsetClone.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_Click()
If Nz(Dcount("CourseId","qryCourse_Details"), 0) = 0 then
MsgBox "No records were found."
Else
DoCmd.OpenQuery "qryCourse_Details"
End If
End Sub

Or

Private Sub cmdDatasheet_Click()
If Nz(DCount("CourseId","qryCourse_Details"*), 0) > 0 then
DoCmd.OpenQuery "qryCourse_Details"
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*******@yahoo.ca> schreef in bericht news:11**********************@z14g2000cwz.googlegr oups.com...
Which procedure would be more efficient, or does it not really matter
which one is used?

Private Sub cmdDatasheet_Click()
If Nz(Dcount("CourseId","qryCourse_Details"), 0) = 0 then
MsgBox "No records were found."
Else
DoCmd.OpenQuery "qryCourse_Details"
End If
End Sub

Or

Private Sub cmdDatasheet_Click()
If Nz(DCount("CourseId","qryCourse_Details"*), 0) > 0 then
DoCmd.OpenQuery "qryCourse_Details"
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
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,...
4
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...
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...
4
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 ...
10
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...
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...
7
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...
1
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...
5
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.