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

How to update a recordset

14
I have this procedure, which opens two recordssets r1 and r2. But there seems to be a problem with the function because the loop does not end and it freezes my ms access application.

can someone please help me.


Private Sub cmdUpdateInventory_Click()

Dim db1 As Database
Dim db2 As Database

Dim rs1 As Recordset
Dim rs2 As Recordset

Set db1 = CurrentDb
Set db2 = CurrentDb

Set rs1 = db1.OpenRecordset("Products")
Set rs2 = db2.OpenRecordset("Select * from tblShipmentdetails where ShipmentID = 3")

rs1.MoveFirst
rs2.MoveFirst

Do While Not rs1.EOF
Do While Not rs2.EOF

rs1.Edit
rs2.Edit


rs1!QuantityOnHand = rs2!QuantityRecieved + rs1!QuantityOnHand

rs1.Update
rs2.Update
rs1.MoveNext
rs2.MoveNext

Loop

Loop

rs1.Close
rs2.Close

End Sub
Nov 15 '07 #1
2 2546
FishVal
2,653 Expert 2GB
Hi, RamanS

No wonder it never ends if the count of records in rs1 more than the count of recirds in rs2. As soon as rs2 will reach EOF the internal cycle will never be entered and the external cycle will never end because rs1 cursor is being moved in the internal cycle.
On the other hand, if rs1.RecordCount<rs2.RecordCount, then the code will fail.
Anyway I can hardly imagine what the code is supposed to do.

Regards,
Fish
Nov 16 '07 #2
Megalog
378 Expert 256MB
It looks like it's simply trying to update inventory (adding received shipment quantity to what's already in stock).

RamanS, Can you post the table relationships? (table names & relevant fields) There's a much easier way to run this in a single loop...
Nov 16 '07 #3

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

Similar topics

0
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get...
2
by: Joseph Markovich | last post by:
I'm having some trouble with VB in Access 2000. I have a form that the user enters in just one number (in this case, it's a base salary) and then the program is going to do a bunch of math (which...
3
by: -Michelle- | last post by:
Hi Using A2003 on XP I am wondering from the MVP's and others, what is the most efficient way (in terms of time to process) of updating data in a table, using the docmd.RunSQL or Recordset ...
3
by: Ken | last post by:
The following code results in a recordset where every other record of tblOne has =True. The recordset count is correct but one record is skipped; exactly half the records are updated to True. Why...
2
by: Nono | last post by:
Hello, I have an Access Database that I want to update using an Excel spreadsheet. When it is new reccords, I know how to do it. Nevertheless when I want to complete the information on a...
5
by: tony010409020622 | last post by:
I just spent 4 months taking a dotnet class where i learned very little. One of the things I did not learn is this: What are the dotnet equivilents of commands such as: Adodc1.Recordset.AddNew...
2
by: DaveN | last post by:
Hi all, I'm trying to update a record in a table with data from text boxes on a form. As a background to this, I managed to add a new record to the table in a similar manner with the following:...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
1
by: sphinney | last post by:
All, I have a ADODB.Recordset in my Access 2002 project. I've been able to successfully add fields to the record set. According the the MS Access help files, I now must update the recordset to...
2
by: Presto | last post by:
I am making a front end mdb so users can enter new members data. I can then import this into the master database on the backend and erase the existing info on the front end to keep the data...
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
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
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
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
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.