473,511 Members | 16,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recordset update is skipping every other record

Ken
The following code results in a recordset where every other record of
tblOne has [Invoice Printed]=True. The recordset count is correct but
one record is skipped; exactly half the records are updated to True.
Why is this occuring and how can I fix it? Using A2K/Win XP.

Thank you.

Code:

Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim strSQL As String

Set cnn = Application.CurrentProject.Connection
Set rst = New ADODB.Recordset
strSQL = "SELECT * from tblOne;"
rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic

rst.Filter = "InvoicePrinted=False"

While Not rst.EOF
rst!InvoicePrinted = True
rst.Update
rst.MoveNext
Wend
Nov 13 '05 #1
3 3236
HJ
I am not 100% sure, but I believe you need to use rst.Edit first:

While Not rst.EOF
rst.Edit
rst!InvoicePrinted = True
rst.Update
rst.MoveNext
Wend

HJ

"Ken" <mo*****@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
The following code results in a recordset where every other record of
tblOne has [Invoice Printed]=True. The recordset count is correct but
one record is skipped; exactly half the records are updated to True.
Why is this occuring and how can I fix it? Using A2K/Win XP.

Thank you.

Code:

Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim strSQL As String

Set cnn = Application.CurrentProject.Connection
Set rst = New ADODB.Recordset
strSQL = "SELECT * from tblOne;"
rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic

rst.Filter = "InvoicePrinted=False"

While Not rst.EOF
rst!InvoicePrinted = True
rst.Update
rst.MoveNext
Wend

Nov 13 '05 #2
Off the top of my head, I'm not sure why it's skipping every other record
(the only thing that comes to mind is that the Update is causing the pointer
in the recordset to move, although that doesn't make sense to me).

However, I think you'd be much better off using an Update statement rather
than going through the recordset as you are:

Dim cmd As ADODB.Command
Dim cnn As ADODB.Connection
Dim strSQL As String

strSQL = "UPDATE tblOne SET InvoicePrinted = True WHERE InvoicePrinted =
False"

Set cnn = Application.CurrentProject.Connection
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = cnn
cmd.CommandText = strSQL
cmd.Execute

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Ken" <mo*****@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
The following code results in a recordset where every other record of
tblOne has [Invoice Printed]=True. The recordset count is correct but
one record is skipped; exactly half the records are updated to True.
Why is this occuring and how can I fix it? Using A2K/Win XP.

Thank you.

Code:

Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim strSQL As String

Set cnn = Application.CurrentProject.Connection
Set rst = New ADODB.Recordset
strSQL = "SELECT * from tblOne;"
rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic

rst.Filter = "InvoicePrinted=False"

While Not rst.EOF
rst!InvoicePrinted = True
rst.Update
rst.MoveNext
Wend

Nov 13 '05 #3
mo*****@hotmail.com (Ken) wrote in message news:<2b**************************@posting.google. com>...
The following code results in a recordset where every other record of
tblOne has [Invoice Printed]=True. The recordset count is correct but
one record is skipped; exactly half the records are updated to True.
Why is this occuring and how can I fix it? Using A2K/Win XP.

Thank you.

Code:

Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim strSQL As String

Set cnn = Application.CurrentProject.Connection
Set rst = New ADODB.Recordset
strSQL = "SELECT * from tblOne;"
rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic

rst.Filter = "InvoicePrinted=False"

While Not rst.EOF
rst!InvoicePrinted = True
rst.Update
rst.MoveNext
Wend


seems like an awful lot of work for something that you could do with either:
a canned update query.
a command object in ADO.
Nov 13 '05 #4

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

Similar topics

9
4333
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
22
2840
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
15553
by: Harold | last post by:
Sat I have a customers table with the fields CustomerID and Customer and I use the recordset.addnew method to add a new record to the table. What is the best way to get the CustomerID of the new...
5
3624
by: msprygada | last post by:
I am having a problem with getting a recordset to fill with data in an Access Data Project from a SQL Server database. Here is the code example that is in the Access help files that I can get to...
3
6860
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
13
3440
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the...
7
4976
by: Eric | last post by:
I want to open up 2 record sets. Then, copy everything from one record set to another (excluding a few fields). Is this possible? I need to exclude my primary key, and fields starting with...
2
5494
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
2
3062
Megalog
by: Megalog | last post by:
Hey all, I have a minor issue I'm trying to figure out (using Access 2007). I'm using a DAO recordset to update a table ("Writeups"), with the results of a bunch of functions I've written up over...
0
7242
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
7418
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
7508
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
5662
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,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.