473,395 Members | 1,783 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,395 software developers and data experts.

Rst.Update does not update

Hi there,

Acc 97 SR2

I hope there is someone out there able to help me with my weird
problem.

I try to update a field in a table with continuous numbers. My problem
is that the code that I run from a button in a form sometimes works,
sometimes it does not. So, I press the button, and the table is update
properly, then I press the button again and this time no calculation
seems to take place and no figures are added to „MyField". The number
of attempts can vary until the result is no update. Sometimes I can
run the code three times after the other and everything is fine, then
the fourth time the table is not updated, sometimes it works only
once, then pressing the button again and again brings no result.

The code is as follows:

Dim db As dao.Database
Dim rs As dao.Recordset
Dim intCounter As Integer

Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM MyTable")

intCounter = 0

rs.MoveLast
rs.MoveFirst

Do While Not rs.EOF
rs.Edit
intCounter = intCounter + 1
rs!MyField = intCounter
rs.Update
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
Set db = Nothing

Any input is highly appreciated!

Thanks,

Sabine
Nov 13 '05 #1
15 5627
Hi Sabine,

this is a weird one. I cant see anything wrong with your code. One thing
to check though. Maybe it is working but you are not realising it. You
need to ensure that you close Mytable and reopen it after each attempt, to
verify that you are looking at the latest data, otherwise your code my be
working but you are not getting to see the result.

If this isnt the case, try switching the following lines from
rs.Edit
intCounter = intCounter + 1
to
intCounter = intCounter + 1
rs.Edit
Its just a guess but this might work. You could also try recoding this in
ADO.

AJC
"Sabine Oebbecke" <Sa*************@unilever.com> wrote in message
news:5c*************************@posting.google.co m... Hi there,

Acc 97 SR2

I hope there is someone out there able to help me with my weird
problem.

I try to update a field in a table with continuous numbers. My problem
is that the code that I run from a button in a form sometimes works,
sometimes it does not. So, I press the button, and the table is update
properly, then I press the button again and this time no calculation
seems to take place and no figures are added to "MyField". The number
of attempts can vary until the result is no update. Sometimes I can
run the code three times after the other and everything is fine, then
the fourth time the table is not updated, sometimes it works only
once, then pressing the button again and again brings no result.

The code is as follows:

Dim db As dao.Database
Dim rs As dao.Recordset
Dim intCounter As Integer

Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM MyTable")

intCounter = 0

rs.MoveLast
rs.MoveFirst

Do While Not rs.EOF
rs.Edit
intCounter = intCounter + 1
rs!MyField = intCounter
rs.Update
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
Set db = Nothing

Any input is highly appreciated!

Thanks,

Sabine

Nov 13 '05 #2
Another thing, your statement
Set rs = db.OpenRecordset("SELECT * FROM MyTable")
doesnt include a sort order. If you dont have a primary key defined this
will open the table in random order.

AJC

"Sabine Oebbecke" <Sa*************@unilever.com> wrote in message
news:5c*************************@posting.google.co m... Hi there,

Acc 97 SR2

I hope there is someone out there able to help me with my weird
problem.

I try to update a field in a table with continuous numbers. My problem
is that the code that I run from a button in a form sometimes works,
sometimes it does not. So, I press the button, and the table is update
properly, then I press the button again and this time no calculation
seems to take place and no figures are added to "MyField". The number
of attempts can vary until the result is no update. Sometimes I can
run the code three times after the other and everything is fine, then
the fourth time the table is not updated, sometimes it works only
once, then pressing the button again and again brings no result.

The code is as follows:

Dim db As dao.Database
Dim rs As dao.Recordset
Dim intCounter As Integer

Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM MyTable")

intCounter = 0

rs.MoveLast
rs.MoveFirst

Do While Not rs.EOF
rs.Edit
intCounter = intCounter + 1
rs!MyField = intCounter
rs.Update
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
Set db = Nothing

Any input is highly appreciated!

Thanks,

Sabine

Nov 13 '05 #3
Hi Andrew,

Many thanks for your input.
Maybe it is working but you are not realising it.
Well, I have checked "MyTable" by closing and reopening it each time I
pressed the button, and "MyField" is definitely empty at times.

I have also already tried switching the lines to
intCounter = intCounter + 1
rs.edit
but that also has got no effect.

I have now taken the code out of the form and included it into a module,
but the behaviour is still the same ... Sometimes "MyField" is updated,
sometimes it is empty.
try recoding this in ADO
I have to admit I wouldn't know how to do it at the moment ...
your statement
Set rs = db.OpenRecordset("SELECT * FROM MyTable")
doesnt include a sort order. If you dont have a primary
key defined this will open the table in random order.


This is intended. I want the code to update the table from the first
entered record to the last.
Well, looking forward to any other ideas which may help to get my update
problem solved.

Thanks again,

Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4
One more hint:

I have also tried with adding a 'MsgBox intCounter' to see whether the
code correctly counts the records, and according to the MsgBox
everything should be fine. It tells me '1', '2', '3', etc., yet
"MyField" is not updated, but empty ...

Rgds,
Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5
The code looks ok. As far as ADO goes, not in Access 97.

Have you done a compact and repair of the file lately? What is the data type
of MyField? Is there an Index on MyField? You say the field is sometimes
left blank. Does it get changed from numbers in the previous run to blanks
when you run the code a second time? Have you tried importing this into a
new mdb file and trying from there? You indicate that you have SR-2 for
Office, but do you also have Jet 3.51 SP3 installed?

--
Wayne Morgan
MS Access MVP
"Sabine" <sa****************@xxxunilever.com> wrote in message
news:42**********@127.0.0.1...
One more hint:

I have also tried with adding a 'MsgBox intCounter' to see whether the
code correctly counts the records, and according to the MsgBox
everything should be fine. It tells me '1', '2', '3', etc., yet
"MyField" is not updated, but empty ...

Rgds,
Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #6
Hi Wayne,
The code looks ok. As far as ADO goes, not in Access 97. That was what I thought ...
Have you done a compact and repair of the file lately? Yes, today.
What is the data type of MyField? Integer.
Is there an Index on MyField? No.
You say the field is sometimes left blank. Does it get changed from numbers in the previous run to blanks when you run the code a second
time?
Yes, this is exactly what happens.
Have you tried importing this into a new mdb file and trying from there?
Well, I more often import the whole mdb (135 MB) into a new one. Also
did this at the beginning of this week, however, did not restrict this
to the tables, queries, forms connected to this problem. Do you think
it's worth a try ?
You indicate that you have SR-2 for Office, but do you also have Jet

3.51 SP3 installed?
Mmhhh, don't know. If you tell me how to check it, I will have a look.

Thanks!

Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #7
Find msjet35.dll in the Windows\System directory. This may be WinNT\System32
or Windows\System32 depending on your version of Windows. If your install is
in a nonstandard directory, you'll have to adjust for that. Right click the
file and choose properties. Click on the version tab. The version should be
3.51.3328.0 or higher.

http://support.microsoft.com/default...b;en-us;172733

Try adding the line

DoEvents

after the Update line. It shouldn't matter, but won't hurt anything either.
I'm just curious if it makes a difference.

--
Wayne Morgan
MS Access MVP
"Sabine" <sa****************@xxxunilever.com> wrote in message
news:42**********@127.0.0.1...
Hi Wayne,
The code looks ok. As far as ADO goes, not in Access 97.

That was what I thought ...
Have you done a compact and repair of the file lately?

Yes, today.
What is the data type of MyField?

Integer.
Is there an Index on MyField?

No.
You say the field is sometimes left blank. Does it get changed from

numbers in the previous run to blanks when you run the code a second
time?
Yes, this is exactly what happens.
Have you tried importing this into a new mdb file and trying from

there?
Well, I more often import the whole mdb (135 MB) into a new one. Also
did this at the beginning of this week, however, did not restrict this
to the tables, queries, forms connected to this problem. Do you think
it's worth a try ?
You indicate that you have SR-2 for Office, but do you also have Jet

3.51 SP3 installed?
Mmhhh, don't know. If you tell me how to check it, I will have a look.

Nov 13 '05 #8
I have now updated the msjet35.dll to V 3.51.3328.0.
Thanks for the link.

I have then also added the line DoEvents after the rs.Update, but no
success.

B U T ! It looks as if I found a solution : After I pressed the button
to run the code, I need to wait for 4 (!) seconds and when I then press
the button again, everything works fine. If I am too quick, "MyField" is
updated with blanks.

So it's a timing issue (with regard to your suggested DoEvent it looks
as if you already thought about this) and I have now to look for some
code which deactivates the button for a few seconds. You don't have a
snip of code for it by chance :-) ?

Regards,

Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #9
Sabine <sa****************@xxxunilever.com> wrote in
news:42**********@127.0.0.1:
I have now updated the msjet35.dll to V 3.51.3328.0.
Thanks for the link.

I have then also added the line DoEvents after the rs.Update,
but no success.

B U T ! It looks as if I found a solution : After I pressed
the button to run the code, I need to wait for 4 (!) seconds
and when I then press the button again, everything works fine.
If I am too quick, "MyField" is updated with blanks.

So it's a timing issue (with regard to your suggested DoEvent
it looks as if you already thought about this) and I have now
to look for some code which deactivates the button for a few
seconds. You don't have a snip of code for it by chance :-) ?

Regards,

Sabine

You don't need the rs.movelast and rs.movefirst statements in the
code from your original message. It could be that the code is
executing the loop before the recordset is ready to accept the
values.

Try removing those two lines.
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #10
Sabine <sa****************@xxxunilever.com> wrote in
news:42**********@127.0.0.1:
I have now updated the msjet35.dll to V 3.51.3328.0.
Thanks for the link.

I have then also added the line DoEvents after the rs.Update,
but no success.

B U T ! It looks as if I found a solution : After I pressed
the button to run the code, I need to wait for 4 (!) seconds
and when I then press the button again, everything works fine.
If I am too quick, "MyField" is updated with blanks.

So it's a timing issue (with regard to your suggested DoEvent
it looks as if you already thought about this) and I have now
to look for some code which deactivates the button for a few
seconds. You don't have a snip of code for it by chance :-) ?

Regards,

Sabine

Another thought. You show no error handler. if it's resume next,
you will never see any message that might help to diagnose the
problem. comment it out if presesnt.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #11
Yes, that is what I was thinking with the DoEvents. Since 4 seconds seems to
do it, let's try something else. There is a command to allow Access/Jet to
write all pending items to disk. Try this in place of the DoEvents.

DBEngine.Idle dbRefreshCache

--
Wayne Morgan
MS Access MVP
"Sabine" <sa****************@xxxunilever.com> wrote in message
news:42**********@127.0.0.1...
I have now updated the msjet35.dll to V 3.51.3328.0.
Thanks for the link.

I have then also added the line DoEvents after the rs.Update, but no
success.

B U T ! It looks as if I found a solution : After I pressed the button
to run the code, I need to wait for 4 (!) seconds and when I then press
the button again, everything works fine. If I am too quick, "MyField" is
updated with blanks.

So it's a timing issue (with regard to your suggested DoEvent it looks
as if you already thought about this) and I have now to look for some
code which deactivates the button for a few seconds. You don't have a
snip of code for it by chance :-) ?

Regards,

Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #12
B i n g o , Wayne, this did the trick - runs perfectly now !

Thanks a lot for your help - much appreciated!

Regards,

Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #13
Hi Bob,

Thanks for your input. As you can see from my latest reply to Wayne, the
line of code

DBEngine.Idle dbRefreshCache

which he suggested to include solved my problem.

However, I would be interested to know why I "don't need the rs.movelast
and rs.movefirst statements in the code." Because, whereever one looks
for examples, there is at least the "rs.movefirst" mentioned.

Rgds,
Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #14
Sabine <sa****************@xxxunilever.com> wrote in
news:42**********@127.0.0.1:
Hi Bob,

Thanks for your input. As you can see from my latest reply to
Wayne, the line of code

DBEngine.Idle dbRefreshCache

which he suggested to include solved my problem.

However, I would be interested to know why I "don't need the
rs.movelast and rs.movefirst statements in the code." Because,
whereever one looks for examples, there is at least the
"rs.movefirst" mentioned.

Rgds,
Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


When using a recordset, the .recordcount property is not
guaranteed valid until the whole recordset has been read. if you
were using a for-next loop to go through the records

example:
for iCtr = 1 to rs.recordcount
!myfield = iCtr
mext

then before starting, a movelast would need doing to ensure that
the loop had the correct end point.

The .movefirst is required if you have done something with the
recordset since you opened it, like a .movelast, a .findfirst or
..findnext.

They are not necessary if you use a while loop instead, on a
newly opened recordset.In examples, I often put extra code to be
on the safe side. the statements in question are probably
remnants of example code. Sometimes good to have, but they slow
execution down if used where not necessary.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #15
Thanks for the clarification, Bob.

I have amended my code accordingly.

Regards,

Sabine

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #16

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

Similar topics

1
by: John Moore | last post by:
Hi, I normally work with Java but I'm interested in using Python as well, particularly for little tasks like doing some massaging of data in a MySQL database. Below is my first attempt. I'm sure...
3
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of...
1
by: Scott Emick | last post by:
I have the following datatables which are related: Transaction TransactionId-Sequence Orders OrderDetails when I process a daTransaction.update(dtTransaction)...
5
by: dani kotlar | last post by:
I run the following code: this.carsBindingSource.EndEdit(); this.carsTableAdapter.Update( this.vehiclesDataSet.Cars ); in order to save changes in the dataset to the database, but the changes...
4
by: kdpo | last post by:
Could someone tell where I can find out if it's true that during UPDFATE SQL Serve deletes data from table, and then inserts new one. Thanks -A
6
JKing
by: JKing | last post by:
I'm using an update query to update a single field in a table. Table1 is part of my normalized table structure. Table2 is used solely as an import table for raw data which I sort and summarize...
1
by: muhremehr | last post by:
hi all can someone one help me why this code does nothing to my database ?!! Sub Main() Dim da As New AdventureWorks_DataDataSetTableAdapters.EmployeeTableAdapter() Dim employees As...
3
by: mercea | last post by:
hi all, i have created a gridview with the select,delete and insert commands working properly. but the update command does not work. when i edit a column and click the update button, it generates...
3
by: asfmendes | last post by:
Hello everyone! I am creating a C# application for tablet pcs and I want to animate some strokes. I am moving the strokes and, after each move, I want to reflect that move in the screen. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
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
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...

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.