Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2008, 06:57 AM
sms sms is offline
Authorized User
 
Join Date: Apr 2008
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
count=recordsetvariable.RecordCount

Here I always fount count=-1.

What should I do?
 
Old April 25th, 2008, 10:22 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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?



mmcdonal

Look it up at: http://wrox.books24x7.com





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 09:18 PM
Connect to VSS check-in Check-out Programatically rhd110 General .NET 6 August 12th, 2007 07:46 AM
Recordset Empty Check Coby Access VBA 2 April 27th, 2007 04:09 PM
How to set Not Null constraint to Null Columns arasu Oracle 1 August 22nd, 2005 10:09 AM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.