473,788 Members | 2,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing Query with NO Result in it

Hi:

Most of the time when I do a query and it has no matches, there is a single blank line in
the result that I can test. I have one query where no result produces a response with NO
lines at all in it. How do I test this kind of query result to determine that there is no
information in it. I am using macros, and on other blank queries I have been checking a
field that will always been filled in and seeing it if isnull.

This query supports a form, and i want to close the form without showing it if there is no
data in it.

Suggestions?

Thanks in advance

John Baker
Nov 12 '05 #1
4 2337
John Baker wrote:
Hi:

Most of the time when I do a query and it has no matches, there is a single blank line in
the result that I can test. I have one query where no result produces a response with NO
lines at all in it. How do I test this kind of query result to determine that there is no
information in it. I am using macros, and on other blank queries I have been checking a
field that will always been filled in and seeing it if isnull.

This query supports a form, and i want to close the form without showing it if there is no
data in it.

Suggestions?

Thanks in advance

John Baker


How do you open the query? WIth a recordset?
Set rst = Currentdb.Openr ecordset("query nam"...)
If rst.Recordcount = 0 then...

or is the query the recorsource of the form.
If Me.Recordsetclo ne.Recordcount = 0 then Cancel = True

Nov 12 '05 #2
On Fri, 16 Jan 2004 21:08:28 GMT in comp.databases. ms-access, John
Baker <Ba******@Veriz on.net> wrote:
Hi:

Most of the time when I do a query and it has no matches, there is a single blank line in
the result that I can test. I have one query where no result produces a response with NO
lines at all in it. How do I test this kind of query result to determine that there is no
information in it. I am using macros, and on other blank queries I have been checking a
field that will always been filled in and seeing it if isnull.

This query supports a form, and i want to close the form without showing it if there is no
data in it.

Suggestions?


This particular query is not updatable, there are many reasons why
this could be. non-updatable queries will not have a blank line in
them for entering new records. There's nothing you can do to change
that except to change the query so that it is updatable.

--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #3
"John Baker" <Ba******@Veriz on.net> wrote in message
news:8l******** *************** *********@4ax.c om...
Hi:

Most of the time when I do a query and it has no matches, there is a single blank line in the result that I can test. I have one query where no result produces a response with NO lines at all in it. How do I test this kind of query result to determine that there is no information in it. I am using macros, and on other blank queries I have been checking a field that will always been filled in and seeing it if isnull.

This query supports a form, and i want to close the form without showing it if there is no data in it.

Suggestions?

Thanks in advance

John Baker

John,
Whether you see a 'blank line' or not might be a bit misleading. The
important point is that, blank line or not, the query returns no records.
The difference is whether you can add to the query or not. Imagine you had
an extremely simple table: tblContacts (ConID, ConName) then with a query
like:

SELECT ConID, ConName FROM tblContacts WHERE ConName="xyz"

you would be able to run this query and, if you had no-one called "xyz" in
your contacts table there would be a single blank row where you could add a
new person (with name="xyz" or anything else you chose). However, if your
query was not updateable, like:

SELECT DISTINCT ConID, ConName FROM tblContacts WHERE ConName="xyz"

Then you would see no rows at all.

In either case, you can inspect the form's RecordsetClone. RecordCount
property to decide if you want to open the form - like this:

Private Sub Form_Open(Cance l As Integer)

On Error GoTo Err_Handler

Cancel = True

If Me.RecordsetClo ne.RecordCount = 0 Then
MsgBox "No Data", vbExclamation, _
"Cannot open form"
Else
Cancel = False
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
This assumes that you have some knowledge SQL and viewing the statement for
your queries and that you know where to insert VBA code. Let me know if
this is an assumption too far.

Fletcher
Nov 12 '05 #4
Thanks again guys..You have resolved the problem!!

Regards

John Baker
Nov 12 '05 #5

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

Similar topics

3
17361
by: Andy Levy | last post by:
Hi Im trying to create a function that tests if a 'Username' exists in a particular table. If the value is found then the code generates 'Username1' as the username, and check if that username exists. If it does, it continues onto generating 'Username2' and so on. <? //testing with username andrew $name = "andrew";
1
1771
by: LRW | last post by:
I'm trying to make an If/Else option in the case a database query comes back with nothing. But when I use the code included below, it always comes back saying there is no result. I'm guessing it's because it's asking if there are any results to the query after it's already finished and the array created. How can I get it to say basically: If there are no database records fitting the query, then do this...otherwise do this? Thanks!! Liam
2
3435
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the new values are updated in all corresponding tables (the function of the pages in question). However, on the page that does the DB update, I also want to do some checks on the data before performing the update. Now, the problem that I am...
11
5449
by: Durai | last post by:
Hi All, I tested "concurrent testing" in MySQL. It works fine. But I couldn't do in PostgreSQL 7.3.4 on HPUX IPF. I got deadlock problem. I used the PHP script to update table( one script increment the column & another one decrement the column). Is the postgres support the concurrent access to update database? I got the following errors: test=# ERROR: deadlock detected ERROR: deadlock detected ERROR: deadlock detected .....
6
5271
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that all querying is done locally. One of the reports we run allows the user to list all invoices within a period. They are also allowed to select a customer code and a product set on
3
1966
by: cover | last post by:
I have a table with 50 fields that receive input depending on whether that input came in from a 'shaker' form or a 'conveyor' form. Input from the 'conveyor' form might populate 25 fields while input from the 'shaker' form will populate another 20-25 fields but not the same fields (however there are about 10 common fields to both). I'd thought about using two tables (one for 'conveyor' and the other for 'shaker') but thought I'd try just...
2
2067
by: chuy08 | last post by:
Basically I am using PHP 5.1.2 with Apache 2.0.5 on a FreeBSD 5.4 box with Mysql 4.1.1 running. I am attempting to write information to a Mysql table called Jabber. I can connect successfully, query data, and write data pretty much without problem. My problem is this. I am trying to do some duplicate checking on this table so I query the dbase with the following:
33
4692
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most of articles I read from different experts and programmers tell me that their "gut feelings" for using stringBuilder instead of string concatenation is when the number of string concatunation is more then N ( N varies between 3 to max 15 from...
6
1329
by: JRough | last post by:
How do I test for no data in a string? I tried if !(isset($data)) and $data =="" and neither one returns the message when there are no records found. Or is it a better idea to do the test at the query level and not let the user get a worksheet with no records? The thing is a user could click the button for excel output even if there are no records on the web page, so I would think in that case they would expect a blank worksheet...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10175
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.