473,762 Members | 6,675 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
30 35888

"Trevor Best" <no****@localho st.invalid> wrote in message
news:43******** *************** @news.zen.co.uk ...
David W. Fenton wrote:
Quintal <rq******@sympa tico.ca> wrote in
news:Xn******** **************@ 207.35.177.135:

In my experience, and as claimed by Randy Harris earlier in this
thread, testing for .EOF always returns the correct answer upon
opening a recordset.

I'm foggy on this, but I seem to remember that you must check both
EOF and BOF to be sure, and that there are some unique circumstances
where it can be an incorrect answer (though I don't remember if it
was a false positive or false negative).

I Googled a bit on this and couldn't find anything, so perhaps it's
just some cobwebs in my brain, but it was my reason for sticking
with checking .RecordCount instead.


Aye, I've ran into this phenom a couple of times, both .eof and .bof
were false yet there were no records, where on Earth it thought the
cursor was I don't know. .RecordCount is more reliable in DAO and broken
in ADO.


With ADO, rs.EOF will never be false if there are 0 records in the
RecordSet. It won't permit a MoveAnywhere and a Find won't change rs.EOF.
As I mentioned earlier, the .RecordCount works only with a KeySet cursor
(don't know if that's what you meant by broken)

Personally, I almost never use rs.BOF. I can't think of any reason to check
it unless you use MovePrevious.
Nov 13 '05 #21
Yes, I find no reason to use BOF.

But RecordCount is returned from Static as well as KeySet Cursor
types.

Complicating this, at least here in Canader, is that no matter to what
value we set the CursorType, when we open a recordset using
CurrentProject. Connection or CurrentProject. AccessConnectio n it is
always opened as adOpenStatic (3), thus always allowing for RecordCount
to be returned.

Perhaps others can confirm this, so that we will not attribute it to
some error here.

(with something like this air code):

Sub test()
Dim c As ADODB.Connectio n
Dim r As ADODB.Recordset
Set c = New ADODB.Connectio n
c.Open CurrentProject. BaseConnectionS tring & ";USER
ID=USERID;PASSW ORD=PASSWORD"
Set r = New ADODB.Recordset
With r
..CursorType = adOpenForwardOn ly '0
..Open "SELECT * FROM FFDBATransactio ns", CurrentProject. Connection
MsgBox .CursorType
MsgBox .RecordCount
..Close

..CursorType = adOpenForwardOn ly '0
..Open "SELECT * FROM FFDBATransactio ns", c
MsgBox .CursorType
MsgBox .RecordCount
..Close
End With
End Sub

Nov 13 '05 #22
It's these seemingly endless number of anomalies that has made me give
up on Access as a front end for MS-SQL.

Nov 13 '05 #23

"lylefair" <ly******@yahoo .ca> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Yes, I find no reason to use BOF.

But RecordCount is returned from Static as well as KeySet Cursor
types.

Complicating this, at least here in Canader, is that no matter to what
value we set the CursorType, when we open a recordset using
CurrentProject. Connection or CurrentProject. AccessConnectio n it is
always opened as adOpenStatic (3), thus always allowing for RecordCount
to be returned.

Perhaps others can confirm this, so that we will not attribute it to
some error here.

(with something like this air code):

Sub test()
Dim c As ADODB.Connectio n
Dim r As ADODB.Recordset
Set c = New ADODB.Connectio n
c.Open CurrentProject. BaseConnectionS tring & ";USER
ID=USERID;PASSW ORD=PASSWORD"
Set r = New ADODB.Recordset
With r
.CursorType = adOpenForwardOn ly '0
.Open "SELECT * FROM FFDBATransactio ns", CurrentProject. Connection
MsgBox .CursorType
MsgBox .RecordCount
.Close

.CursorType = adOpenForwardOn ly '0
.Open "SELECT * FROM FFDBATransactio ns", c
MsgBox .CursorType
MsgBox .RecordCount
.Close
End With
End Sub


Strange indeed. You're correct, of course, about adOpenStatic also providing
the RecordCount.

I always use this sort of syntax, rather than specifying the CursorType
separately (not for any good reason, it's the way I got used to doing it):

rs.Open SQL, CurrentProject. Connection, adOpenKeyset, adLockReadOnly

It seems to always use the cursor type I specify. adOpenForwardOn ly if I
just leave the cursor type off.

Nov 13 '05 #24

"lylefair" <ly******@yahoo .ca> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
It's these seemingly endless number of anomalies that has made me give
up on Access as a front end for MS-SQL.


Can I ask, what you find preferable for the front end?

Nov 13 '05 #25
What do you get when running something like this?
Dim rs As ADODB.Recordset
Dim SQL As String
SQL = "SELECT * FROM FFDBATransactio ns WHERE TotalAmount>100 "
Set rs = New ADODB.Recordset
rs.Open SQL, CurrentProject. Connection, adOpenKeyset, adLockReadOnly

Debug.Print "Cursor Type Is Keyset? ", rs.CursorType = adOpenKeyset
I get False

Debug.Print "Cursor Type Is Static? ", rs.CursorType = adOpenStatic
I get True

Nov 13 '05 #26
ASP and HTA.

Nov 13 '05 #27

"lylefair" <ly******@yahoo .ca> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
What do you get when running something like this?
Dim rs As ADODB.Recordset
Dim SQL As String
SQL = "SELECT * FROM FFDBATransactio ns WHERE TotalAmount>100 "
Set rs = New ADODB.Recordset
rs.Open SQL, CurrentProject. Connection, adOpenKeyset, adLockReadOnly

Debug.Print "Cursor Type Is Keyset? ", rs.CursorType = adOpenKeyset
I get False

Debug.Print "Cursor Type Is Static? ", rs.CursorType = adOpenStatic
I get True


Very strange indeed. I'm using Access 2000, in case that makes a
difference.

---------------------------------------------------
Dim rs As ADODB.Recordset
Dim SQL As String
SQL = "SELECT * FROM Itineraries"
Set rs = New ADODB.Recordset
rs.Open SQL, CurrentProject. Connection, adOpenKeyset, adLockReadOnly
Debug.Print "Cursor Type Is Keyset? ", rs.CursorType = adOpenKeyset
Debug.Print "Cursor Type Is Static? ", rs.CursorType = adOpenStatic
rs.Close
---------------------------------------------------
Cursor Type Is Keyset? True
Cursor Type Is Static? False

---------------------------------------------------

I tried it the other way, out of curiosity.

---------------------------------------------------
Dim rs As ADODB.Recordset
Dim SQL As String
SQL = "SELECT * FROM Itineraries"
Set rs = New ADODB.Recordset
rs.Open SQL, CurrentProject. Connection, adOpenStatic, adLockReadOnly
Debug.Print "Cursor Type Is Keyset? ", rs.CursorType = adOpenKeyset
Debug.Print "Cursor Type Is Static? ", rs.CursorType = adOpenStatic
rs.Close
---------------------------------------------------
Cursor Type Is Keyset? False
Cursor Type Is Static? True
---------------------------------------------------

I also tried it without specifying cursor type. They both showed false.

Nov 13 '05 #28
Hmmmmm.
I tried this on Access 2002 and Access 2003 with local and remote adps
and local mdbs on two different machines 50 km apart with various
manifestations of the ADO library from 2.1 to 2.8.
I always go a Static cursor type.
Perhaps, I am missing something; I will check and recheck and post
anything I find.

Nov 13 '05 #29
"lylefair" <ly******@yahoo .ca> wrote in
news:11******** *************@g 14g2000cwa.goog legroups.com:
Yes, I find no reason to use BOF.


It would be helpful if those posting on this subject would clearly
indicate whether they are talking about DAO or ADO recordsets.

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

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

Similar topics

2
1763
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
4425
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
1311
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
2650
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
6130
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
1734
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
2353
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
9377
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
9989
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
9925
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
9811
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...
1
7358
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
6640
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
5266
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...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3509
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.