Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old April 24th, 2008, 07:57 AM
sms sms is offline
Authorized User
Join Date: Apr 2008
Location: Satdobato, , Nepal.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to check whether recordset is null?

I am getting problem with recordset.
After select query, what I want to do is to check whether the recordset contains data or not.

I have used code like this.

Dim count as Integer

Here I always fount count=-1.

What should I do?
Reply With Quote
  #2 (permalink)  
Old April 25th, 2008, 11:22 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

Normally what you would do is something like:

rs.Open etc...

If rs.RecordCount <> 0 Then
   'process only if there is data in the recordset

End If

You say you are always getting RecordCount equaling -1, which means there is data in the recordset. Are there times when the code runs and throws an error because there is no data in the recordset (recordcount = 0)?

If you want to take the long way around, you could always do "SELECT Count(PKField) As PKCount FROM tblMyTable WHERE..." and then, if rs("PKCount") <> 0... then run the rest of the code.

What is the code that you are running that is causing problems with emptry recordsets?


Look it up at: http://wrox.books24x7.com
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for null primary key value? yukijocelyn ASP.NET 2.0 Basics 6 August 14th, 2007 10:18 PM
Connect to VSS check-in Check-out Programatically rhd110 General .NET 6 August 12th, 2007 08:46 AM
Recordset Empty Check Coby Access VBA 2 April 27th, 2007 05:09 PM
How to set Not Null constraint to Null Columns arasu Oracle 1 August 22nd, 2005 11:09 AM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 03:31 PM

All times are GMT -4. The time now is 10:15 PM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.