473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Please help me with recordset!

I opened the recordset by all the rules. There should be a few fields, and it turns out, only one !!!! Head already broke .....

Code:
Expand|Select|Wrap|Line Numbers
  1. dim rst as DAO.Recordset
  2.  
  3. dim strSQL as String
  4.  
  5. strSQL = "SELECT table.Name FROM table WHERE ID > 3"
  6. set str = CurrentDB.OpenRecordset(strSQL, dbOpenDynaset)
  7. Debug.Print rst.Recordcount
  8. set rst = Nothing
Resalt of Debug.Print rst.Recordset always =1
Jun 6 '16 #1
2 942
jforbes
1,107 Expert 1GB
Fields are not Rows. You can think of Fields as columns in your dataset. Since you are selecting:
Expand|Select|Wrap|Line Numbers
  1. SELECT table.Name FROM table WHERE ID > 3]
you are only asking for one field to be returned.

But, I don't think that is what you are asking about. It appears that you are debug.printing the RecordCount and are confused as to why you are only getting one record in the RecordCount. There are a couple reasons you would get this. The first is that there is only one record that meets your Where Clause:
Expand|Select|Wrap|Line Numbers
  1. SELECT table.Name FROM table WHERE ID > 3
Make sure there is more than one record with an ID over 3.

The second is that the RecordCount property is unreliable until all the records have been viewed/accessed This link explains it fairly well: How to: Count the Number of Records in a DAO Recordset ... There is a big note in the middle of the article specific to what you are running into.

If you put in a
Expand|Select|Wrap|Line Numbers
  1. rst.MoveLast
before you attempt to use the RecordCount Property, and you actually have more than one record, you should get the correct results.

lastly, I think str is a typo, and should be rst:
Expand|Select|Wrap|Line Numbers
  1. set str = CurrentDB.OpenRecordset(strSQL, dbOpenDynaset)
If you put Option Explicit at the top of your code modules, typos like this will be pointed out by Access: Option Explicit Statement
Jun 6 '16 #2
NeoPa
32,556 Expert Mod 16PB
Require Variable Declaration should help with that last part.

You can also find a link to it in Before Posting (VBA or SQL) Code.

People will generally be very hesitant about working with somebody who posts code they've typed in directly - rather than copy/pasted from their project.
Jun 6 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use...
7
by: David Berry | last post by:
I'm trying to use a recordset inside of a function but I'm getting an "object required 'adoRS" error. At the top of the page I create my recordset, ex: dim strConnection, adoCN, adoRS, strSQL...
8
by: dmiller23462 | last post by:
My brain is nuked....Can anybody tell me right off the bat what is wrong with this code? Along with any glaring errors, please let me know the syntax to display a message (Response.Write would be...
7
by: Arpan | last post by:
Assume that an ASP page has 3 SQL queries. Can a recordset object be populated with the records of all these 3 queries at the same time? Please note that the 3 queries are distinct queries, not...
4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
5
by: Simone | last post by:
Hello I hope you guys can help me. I am very new to ADO... I am creating a ADODB connection in a module and trying to access it from a command button in a form. Function fxEIDAssgn(plngEID As...
22
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
2
by: Yaara Mac | last post by:
Hi all, I need some help with using recordset.bof / oef. I'm using HTML file to display XML records page by page. I need to disable the moveNext button once it reaches the end of the file...
4
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I think I'm done for now,... Is it possible to insert recordset data in a javascript, for instance I have a javascript...
25
by: jmeni | last post by:
I am working on a Loan Amortization using Access 2000 format and have generated a Repayment Schedule. I have some tables, queries and forms already created and attached here. I will base my...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.