PC Review


Reply
Thread Tools Rate Thread

Cannot open recordset

 
 
Nova
Guest
Posts: n/a
 
      5th Jan 2010
This is my code

Dim Cnx As ADODB.Connection
Dim Rst As ADODB.Recordset
Dim StrCnx As String
Dim CmdRst As String
Dim N As Integer

CmdRst = "SELECT * FROM MatStock WHERE MatID='" & MatIDSel & "';"

Set Cnx = CurrentProject.Connection
Set Rst = New ADODB.Recordset

Rst.Open CmdRst, Cnx, adLockReadOnly, -1
N = Rst.RecordCount
Msgbox N
It works, I can get N
After that I change code from adlockreadonly to adLockPessimistic,-1
but the msgbox show me -1
I don't understand (I change code because I want to update some field in
recordset
How can I correct it?
 
Reply With Quote
 
 
 
 
Tom van Stiphout
Guest
Posts: n/a
 
      5th Jan 2010
On Mon, 4 Jan 2010 21:59:02 -0800, Nova
<(E-Mail Removed)> wrote:

For performance reasons the RecordCount is not populated until all
rows are read, and Access (ADO) will lazily load the records. You can
force it by doing:
if not rst.eof then rst.movelast

Of course if all you wanted is a count, you can use a different query:
select count(*) from ... etc.

-Tom.
Microsoft Access MVP


>This is my code
>
> Dim Cnx As ADODB.Connection
> Dim Rst As ADODB.Recordset
> Dim StrCnx As String
> Dim CmdRst As String
> Dim N As Integer
>
> CmdRst = "SELECT * FROM MatStock WHERE MatID='" & MatIDSel & "';"
>
> Set Cnx = CurrentProject.Connection
> Set Rst = New ADODB.Recordset
>
> Rst.Open CmdRst, Cnx, adLockReadOnly, -1
> N = Rst.RecordCount
> Msgbox N
> It works, I can get N
> After that I change code from adlockreadonly to adLockPessimistic,-1
>but the msgbox show me -1
> I don't understand (I change code because I want to update some field in
>recordset
>How can I correct it?

 
Reply With Quote
 
Nova
Guest
Posts: n/a
 
      7th Jan 2010
Thanks it works

"Tom van Stiphout" เขียน:

> On Mon, 4 Jan 2010 21:59:02 -0800, Nova
> <(E-Mail Removed)> wrote:
>
> For performance reasons the RecordCount is not populated until all
> rows are read, and Access (ADO) will lazily load the records. You can
> force it by doing:
> if not rst.eof then rst.movelast
>
> Of course if all you wanted is a count, you can use a different query:
> select count(*) from ... etc.
>
> -Tom.
> Microsoft Access MVP
>
>
> >This is my code
> >
> > Dim Cnx As ADODB.Connection
> > Dim Rst As ADODB.Recordset
> > Dim StrCnx As String
> > Dim CmdRst As String
> > Dim N As Integer
> >
> > CmdRst = "SELECT * FROM MatStock WHERE MatID='" & MatIDSel & "';"
> >
> > Set Cnx = CurrentProject.Connection
> > Set Rst = New ADODB.Recordset
> >
> > Rst.Open CmdRst, Cnx, adLockReadOnly, -1
> > N = Rst.RecordCount
> > Msgbox N
> > It works, I can get N
> > After that I change code from adlockreadonly to adLockPessimistic,-1
> >but the msgbox show me -1
> > I don't understand (I change code because I want to update some field in
> >recordset
> >How can I correct it?

> .
>

 
Reply With Quote
 
 
 
Reply

« Query Question | 12 »
Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form on open shows 2 records exist when recordset not open kfguardian Microsoft Access Form Coding 3 5th Jun 2008 03:55 PM
How do you doubleclick on a recordset to open recordset in form vi =?Utf-8?B?Si4gS2VnZ2VybG9yZA==?= Microsoft Access Form Coding 3 4th May 2007 08:56 PM
Open form with filter will not open to filtered recordset May via AccessMonster.com Microsoft Access Form Coding 1 3rd Aug 2006 11:45 PM
How to open recordset =?Utf-8?B?TWFkaHVyaQ==?= Microsoft Access VBA Modules 1 13th Jul 2005 02:02 AM
Can't open recordset Robert Chapman Microsoft Access Getting Started 3 9th Feb 2004 03:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 AM.