Solved

Recordset.Recordcount = -1 ??????

Posted on 2002-04-25
3
125 Views
Last Modified: 2010-05-02
Hi!

I make a query into a recordset. It isn't Nothing, but when I pick it's RecordCount, it always returns with -1.

Why?

  strSQL = "Select * from Table"
 
  Set guestBookData = New ADODB.Recordset
 
  guestBookData.Open strSQL, conn
 
  c = guestBookData.RecordCount
  MsgBox c

--------------------
c = -1, but rs isn't empty, I can get the data from it.
0
Comment
Question by:holdkoros
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
Comment Utility
That is because the default options on recordset.open is a ForwardOnly recordset, use:

guestBookData.Open strSQL,conn,adOpenStatic,adLockReadOnly

For a scrollable recordset, optionally set the cursorlocation to clientside.

guestBookData.CursorLocation = adUseClient

Before opening the recordset.
0
 
LVL 1

Expert Comment

by:gron
Comment Utility
When you work with linked TableDef objects, the RecordCount property setting is always –1.
Using the Requery method on a Recordset object resets the RecordCount property just as if the query were re-executed.
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
gron, that is DAO stuff you are talking about, ADO is a different beast (similar in some respects but not the same).
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now