473,406 Members | 2,281 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,406 software developers and data experts.

Open a dao recordset

I am writing a function in which I need to open a sorted recordset. I am
using a SQL statemenet in the db.OpenRecordset line, but it is only
returning one record, when executing the query outside the function should
return 153. Here is the basic code...
Function FirstOpen() As Integer

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strQry As String

strQry = "SELECT TblCDS.* FROM TblCDS;"

Set db = CurrentDb
Set rs = db.OpenRecordset(strQry, dbOpenDynaset)
MsgBox rs.RecordCount

rs.Close
Set rs = Nothing

End Function

If I use the table name instead of the SQL, the message box returns the
correct count. Why doesn't this work?
Aug 12 '07 #1
1 2262
try adding these lines:

Set rs = db.OpenRecordset(strQry, dbOpenDynaset)
rs.MoveLast
rs.MoveFirst

to fully populate the recordset

William Hardin wrote:
I am writing a function in which I need to open a sorted recordset. I am
using a SQL statemenet in the db.OpenRecordset line, but it is only
returning one record, when executing the query outside the function should
return 153. Here is the basic code...
Function FirstOpen() As Integer

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strQry As String

strQry = "SELECT TblCDS.* FROM TblCDS;"

Set db = CurrentDb
Set rs = db.OpenRecordset(strQry, dbOpenDynaset)
MsgBox rs.RecordCount

rs.Close
Set rs = Nothing

End Function

If I use the table name instead of the SQL, the message box returns the
correct count. Why doesn't this work?

Aug 12 '07 #2

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

Similar topics

4
by: Dalan | last post by:
I presume that using an open recordset method is the preferred method of accomplishing what I'm trying to do. Of course, if there are other options that would work, feel free to share them. I...
13
by: Seth Spearman | last post by:
Hey guys, I have the following code: '****************************************************** If Not Me.NewRecord Then Dim rs As DAO.Recordset Dim strBookmark As String Set rs =...
2
by: Colleyville Alan | last post by:
I ran into problems in an app in which I received a msg of "cannot lock the table, it is in use by another user". It turns out that I had opened a recordset with a command like set rstmyrecs =...
2
by: Sunil Korah | last post by:
I am having some trouble with opening recordsets. I have used code more or less straight from the access help. But still I am getting some errors. I am unable to work out what exactly I am doing...
0
by: solar | last post by:
I am creating a new recordset in 2 tables, orders and order details.Obviously i have to open the recordset for two tables.Shall i open the recordset for the table order details and when shall i...
6
by: blue875 | last post by:
Hello helper people who are smarter than me: I have a form that needs to submit multiple queries to different tables during one Sub's execution. Some sections are as simple as: 1| With rst 2|...
2
by: Jim M | last post by:
I rarely deal with recordsets directly with code, since I usually use Access queries, so be patient with this question. I want to open a recordset with various default variables used by my program....
23
by: PW | last post by:
Hi, I'd like to close a recordset and set the database to nothing if a recordset is open if an error has occured. Leaving a recordset open and a database open isn't a good idea, right? ...
8
by: metalheadstorm | last post by:
ok ive set up a connection between my access db ( 97) and my vb6 interface and this is what i got form_load Data6.DatabaseName = App.Path & "\cjmillers.mdb" Data6.RecordSource = "select * from...
2
by: Kosmos | last post by:
I am opening the following connections as such although I am only referring to the first connection for this question: Dim con1 As ADODB.Connection Dim con2 As ADODB.Connection Dim recSet1 As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.