473,387 Members | 1,512 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,387 software developers and data experts.

How to compare to an empty recordset

65
Hi,

I'm trying to get some values from one table to an other. Now I select all dates from one table and I search with them in another table. When there is a record found for that date it should perform a query. But when there is nog record foud for that date is return empty. How do I compare to that??

My code for now:
Expand|Select|Wrap|Line Numbers
  1. Set rst = db.OpenRecordset("SELECT DISTINCT Datum FROM Longfunctie;")
  2.     Do Until rst.EOF
  3.         Set rst2 = db.OpenRecordset("SELECT eadnr, parameter, Waarde FROM PatParameters WHERE Datum = " & rst.Fields(0).Value & ";")
  4.         If (IsEmpty(rst2.Fields(0).Value)) Then
  5.             Debug.Print rst.Fields(0) & " " & rst2.Fields(0).Value & " " & rst2.Fields(1).Value & " " & rst2.Fields(2).Value
  6.         End If
  7.         rst.MoveNext
  8.     Loop
  9.  
Sep 20 '07 #1
3 2426
barry07
47
Although you say empty Recordset I think you mean empty Record in which case I would use the Nz function which returns a specified value when the original value is null. It's one of the peculiarities of Access that I have discovered that nulls aren't always matched by expressions such as "isNull" or ="", or even IsEmpty.

This, however is a surefire method of detecting a null:

Expand|Select|Wrap|Line Numbers
  1. If Nz(rst2.Fields(0),"") = ""  Then

If you really mean empty Recordset then test for rst.RecordCount <1

Hope this helps.
Sep 20 '07 #2
Twanne
65
Hi,

I've tried tthat to, but it didn't work either. The problem is that the recordset is empty, not the record itself. So it is a recordset without records.

I've searched some more on other sites :p and found that it is possible to check the recordset itself with the .EOF and .BOF parameters. If they are both true than there is no record in the recordset. I've only found it after some hours of searching.

Thanx for the help anyway.

Greetz
Twanne

Living is hard, dying is easier.
Sep 20 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
You need to relook at your logic. If no matching date then there is no record to be found or printed. This should work to catch empty returns for the second recordset.

Expand|Select|Wrap|Line Numbers
  1. Set rst = db.OpenRecordset("SELECT DISTINCT Datum FROM Longfunctie;")
  2.     Do Until rst.EOF
  3.     Set rst2 = db.OpenRecordset("SELECT eadnr, parameter, Waarde FROM PatParameters WHERE Datum = " & rst.Fields(0).Value & ";")
  4.     rst2.MoveLast
  5.     rst2.MoveFirst
  6.     If rst2.RecordCount = 0 Then
  7.         ' No record found
  8.     Else
  9.         Debug.Print rst.Fields(0) & " " & rst2.Fields(0).Value & " " & rst2.Fields(1).Value & " " & rst2.Fields(2).Value
  10.     End If
  11.     rst.MoveNext
  12.     Loop
  13.  
Oct 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Simon Gare | last post by:
Hi I need to compare a dynamic field in an asp page to a field in another table, if there is no match then i would like to chane the row colour ( see code below). The problem Im having is...
7
by: Jean | last post by:
Hello, I have a form that performs a search, according to criteria that a user enters into the text boxes. When the user clicks on „Search", a SQL string (say strSQL) is built up with the...
0
by: dfs9 | last post by:
In the article "Delete Duplicate Records From Access Tables" By Danny Lesandrini writes the following: This final suggestion is the most flexible and accurate. Given any table, it generates a...
4
by: dfs9 | last post by:
In the article "Delete Duplicate Records From Access Tables" By Danny Lesandrini writes the following: This final suggestion is the most flexible and accurate. Given any table, it generates a...
30
by: S. van Beek | last post by:
Dear reader A record set can be empty because the condition in the query delivers no records. Is there a VBA code to check the status of a record set, record set empty
0
ADezii
by: ADezii | last post by:
When you create a Recordset, you may want to know immediately whether that Recordset actually contains any Rows. There are Recordsets that don't return any Rows and you may need to take different...
6
by: Twanne | last post by:
I've got this date I queryd from a table, and I want to compare this date to the same field as where it came from but it keeps returning an empty recordset. Can anyone help me. Set rst2 =...
2
by: hackmagic | last post by:
Hi, i have a form that normally has a Recordset containing only one record bound to it. i have replaced the navigation buttons with my own and the 'New Record' button assigns an empty Recordset...
4
by: ipez75 | last post by:
Hello everyone, I have a web application written in asp 6.0, my problem is that I execute a sql server store procedure and I get an empty recordset, while executing the same sp on query anlyzer I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
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...
0
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,...

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.