473,738 Members | 7,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check on empty record set in VBA

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
(no records) or with records?

Thanks for any help.

Simon van Beek
Nov 13 '05 #1
30 35878

S. van Beek wrote:
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
(no records) or with records?

Thanks for any help.

Simon van Beek


Nov 13 '05 #2

S. van Beek wrote:
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
(no records) or with records? Thanks for any help.

Simon van Beek


If your recordset is rs (say) then

rs.movelast
if rs.recordcount - 0 then
'no rows
else
'rows returned
end if

HTH
Jeff

Nov 13 '05 #3

S. van Beek wrote:
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
(no records) or with records? Thanks for any help.

Simon van Beek


If your recordset is rs (say) then

rs.movelast
if rs.recordcount = 0 then
'no rows
else
'rows returned
end if

HTH
Jeff

Nov 13 '05 #4

S. van Beek wrote:
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
(no records) or with records? Thanks for any help.

Simon van Beek


If your recordset is rs (say) then

rs.movelast
if rs.recordcount = 0 then
'no rows
else
'rows returned
end if

HTH
Jeff

Nov 13 '05 #5
S. van Beek wrote:
Is there a VBA code to check the status of a record set, record set empty
(no records) or with records?


I do this two ways, one for when a form with an underlying
recordset/query/sql statement is opened and the other when I'm doing
operations on the recordset and the form is open.

The first, on _FIRST_ opening the form:

if forms!frmName.r ecordsetclone.e of then

'no records, do your stuff. If this is used in the on open event, set
cancel = true to avoid opeing the form.

I don't like using the recordsetclone for checking this sort of thing
when the form is open. Too much fiddling with having to make sure .move
first, etc.

I use a function like this (air code)

Function fCheckRecords() as Integer (or long if large numebrs of records
are involved)

dim strS as string
dim rst as dao.recordset
dim dbs as dao.database
'I personally don't use database variables in procedures anymore - I
use the David Fenton/Michka function see http://tinyurl.com/8nvl3

set dbs = Access.currentd b

strS = "Select count(*) as No from <enter rest of your tables and
criteria - idea is to have a query that returns one value)

set rst = dbs.openrecords et(strs, dbopensnapshot)

fCheckRecords = rst.fields!No

rst.close

dbs.close

set rst = ntohing

set dbs = nothing

end function

This function is used like:

If fcheckRecords = 0 then <do stuff for empty recordset>

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #6
Immediately after opening the DAO Recordset, all I've ever used is

If rs.BOF And rs.EOF Then
' the recordset is empty
End If

Nov 13 '05 #7
Immediately upon opening

EOF <=> no records
BOF <=> no records

(if paid by word)
BOF AND EOF <=> no records

Nov 13 '05 #8
jb********@aol. com wrote in
news:11******** **************@ g43g2000cwa.goo glegroups.com:
S. van Beek wrote:
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 (no records) or with records?


If your recordset is rs (say) then

rs.movelast
if rs.recordcount = 0 then
'no rows
else
'rows returned
end if


The original poster does not specify DAO or ADO.

In DAO, you don't need to .MoveLast to know if the recordset is
empty. You only need to .MoveLast when you want an accurate count of
the records returned. If there are records returned, the recordcount
will always be 1 or more, and when none are returned, it will always
be zero, no matter whether you .MoveLast or not.

ADO is different. It returns different things. I don't use ADO, so I
can't tell you what it returns, but the help file for the ADO
recordset object ought to give you the information you need.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9
Tim Marshall <TI****@PurpleP andaChasers.Moe rtherium> wrote in
news:dg******** **@coranto.ucs. mun.ca:
S. van Beek wrote:
Is there a VBA code to check the status of a record set, record
set empty (no records) or with records?


I do this two ways, one for when a form with an underlying
recordset/query/sql statement is opened and the other when I'm
doing operations on the recordset and the form is open.

The first, on _FIRST_ opening the form:

if forms!frmName.r ecordsetclone.e of then

'no records, do your stuff. If this is used in the on open
event, set
cancel = true to avoid opeing the form.

I don't like using the recordsetclone for checking this sort of
thing when the form is open. Too much fiddling with having to
make sure .move first, etc.


Why not just check Me.Recordsetclo ne.RecordCount? So far as I know,
that's always going to be accurate in the same way as .RecordCount
for any DAO recordset, no?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #10

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

Similar topics

2
1762
by: perryche | last post by:
If a report yield 0 record, I will get an #error message on a calculation field. How to display a 0 instead of #error on that field? Thanks. Perry
3
4424
by: Andrew Banks | last post by:
I'm outputting data from a SQL server database to a web form (C#). How can I detect if a value is null in the database? Thanks
1
1309
by: Shapper | last post by:
Hello, I need to check if a textbox is returning an empty value. When I use Response.Write(myTextBox.Text) I get the written value. However, when I use the code: If myTextBox.Text Is Nothing Then Response.Write("Empty") End If
1
4330
by: Cesar Zapata | last post by:
Hi, I have a a bound subform and what i'm trying to do is do check if some criteria applies before saving the record and trigger a macro. basically this is what I got. Date Received InStock UnitPrice
8
2649
by: lmurgas | last post by:
FormA = List of organization records bound to table FormB = Tabbed form with details of organization and all other related entities, such as orders, contacts, invoices, (all as subforms bound to FormB on primary key) FormC = Pop-up to add/edit/delete a record from one of the associated entities. For example, there is a pop-up to add a new contact record to an Org. Current Behavior: 1. Open FormA and remains active 2. Double click on row...
6
2357
jinalpatel
by: jinalpatel | last post by:
I am using following code for searching records. 'Purpose: Build up the criteria string form the non-blank search boxes, and apply to the form's Filter. 'Notes: 1. We tack " AND " on the end of each condition so you can easily add more search boxes; _ we remove the trailing " AND " at the end. Dim strWhere As String 'The criteria string. Dim lngLen As...
9
6128
by: Dhiru1009 | last post by:
Hi guys, I am trying to build a user registration form using PHP and MYSQL but encountring a problem. When I click on submit with empty fields it adds records to database also it doesn't matter what information I put it always add records to database when I click on submit. What can I do to make sure user will not be able to add records to database until he enters the right information? I am posting my code for you guys to have a look...
0
1733
by: sumitdipsite2005 | last post by:
I am trying to use VB6 as a middleware between two 3rd party applications. "App. A" ----> VB6 ------> "App B" i am having no trouble sending data from VB to the "App B". But i am having some trouble in reading data from "App A".
1
2351
by: frensan | last post by:
Hello, Not sure if this is the right forum, apologies in advance if it isn't. I am using adodb to connect to oracle database. My VB script returns an empty record for a sql query, but when I issue the same query from SQL Developer or from sql command prompt, the query returns a row. The machine has MDAC 2.8 and Oracle 10 db. I read here http://www.mofeel.net/27-microsoft-public-data-ado/3080.aspx# that there is a known problem with MDAC...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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
9335
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...
1
9263
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8210
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
6751
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
4570
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...
1
3279
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
3
2193
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.