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

Movefirst not working nested loops,, movefirst is not working so that loop can restar

Expand|Select|Wrap|Line Numbers
  1. Do While Not rss.EOF
  2. Do While Not prers.EOF
  3.  
  4. If rss.Fields(0).Value = prers.Fields(1).Value Then
  5. ///match found   
  6. some action..............
  7.  
  8. If Not rss.EOF Then rss.MoveNext
  9. prers.MoveFirst          
  10.  
  11. Else
  12. If Not prers.EOF Then prers.MoveNext     /match not found, reched with against another prers value
  13.  
  14. End If
  15.  
  16. Loop
  17.  
  18. prers.MoveFirst
  19.  
  20. //////////some action
  21.  
  22. If Not rss.EOF Then rss.MoveNext
  23. prers.MoveFirst
  24.  
  25. Loop
  26.  
  27.  
  28.  
movefirst is not working so that loop can restard from first record each time, any help would be highly appriciated.
Aug 15 '10 #1
4 2691
ADezii
8,834 Expert 8TB
Subscribing, will return later.
Aug 15 '10 #2
FishVal
2,653 Expert 2GB
  • What is the type of recordset cursor?
  • Thwe code looks quite kludge. What does it actually do?
  • If the aim is to find matches, then did you consider to use table join instead of recordsets nested iteration?
Aug 15 '10 #3
ADezii
8,834 Expert 8TB
I, like FishVal, am also confused as to exactly what your are looking for. If you are simply looking to find Matches on Fields from 2 Data Sources, using Nested Recordset Loops, then this should at least get you started. The following code will search the 1st Field of every Record in Table1 against possible matches on the 2nd Field in every Record of Table2. This is simply a guideline, kindly make your objectives a little clearer.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rss As DAO.Recordset
  3. Dim prers As DAO.Recordset
  4.  
  5. Set MyDB = CurrentDb
  6. Set rss = MyDB.OpenRecordset("Table1", dbOpenForwardOnly)
  7. Set prers = MyDB.OpenRecordset("Table2", dbOpenSnapshot)
  8.  
  9. With rss
  10.   Do While Not .EOF
  11.     Do While Not prers.EOF
  12.       If .Fields(0) = prers.Fields(1) Then
  13.         Debug.Print "Match on: " & .Fields(0) & " ==> " & prers.Fields(1)
  14.       End If
  15.         prers.MoveNext
  16.     Loop
  17.       prers.MoveFirst
  18.       .MoveNext
  19.   Loop
  20. End With
  21.  
  22. prers.Close
  23. rss.Close
  24. Set prers = Nothing
  25. Set rss = Nothing
Aug 15 '10 #4
Thank you all for your reply.
I am beginner in access VBA, as for the cursor type I have declared recordset as following

Dim precn As ADODB.Connection
Set precn = CurrentProject.Connection
Dim prers As New ADODB.Recordset
prers.ActiveConnection = precn
prers.CursorType = adOpenDynamic
prers.LockType = adLockOptimistic

-Actually It is simple credit based sales and purchase system; I have table receivable _closing which is updated last date of every month with autoexec by using pasted code and saves pending balance.
-Sales table has all the record of transactions made in this month.
Now end of each month previously pasted code will update Receivable _ closing Table using autoexec.
First Case: it will check matching record and add one by one in receivable closing table.
Second Case : A client has pending balance but did not do any new transaction in this month , so one do while loop in the pasted code will check each record of receivable closing against sale. If found it will add
If not found
It means he is a new client or has zero pending balance so it will add record in receivable closing accordingly.
Third case:Some clients would have pending balance in Receivable closing and have no activity in last months, and I want this pending balance to be save again in Receivable closing with new closing date.
So another loop will check this thing by using same recordset “ PRERS “which is not pasted.
So prers have to movefirst many time, which is not working I don’t know why. 
I hope you can help
Thanks
Aug 16 '10 #5

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

Similar topics

3
by: Oleg Leschov | last post by:
Could there be means of exiting nested loops in python? something similar to labelled loops in perl.. I consider it irrating to have to make a flag for sole purpose of checking it after loop if...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
10
by: Pavan | last post by:
Hi i have two nested loops as shown below: 1. for(i=0;i<=1000;i++) { for(i=0;i<=100;i++) { .....; .....; }
17
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html Why is C# 500% slower than C++ on Nested Loops ??? Will this problem be solved in...
10
by: Roshawn | last post by:
Hi, I am experimenting with nested For...Next loops. My code looks like this: Dim i as Byte Dim itm as Byte For i = 0 to 9 For itm = 0 to 9 'code omitted
5
by: Uday Deo | last post by:
Hi everyone, I am looping through 4 nested loops and I would like to break in the inner most loop on certain condition and get the control on the 2 nd loop instead of 3rd loop. Here is briefly...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
3
by: tzuriel | last post by:
Hello all, I think nested loops will do what I want, but I can't seem to get them right. I have two tables, members and casts. I run a query as follows: $sql_query="SELECT DISTINCT...
4
by: toddlahman | last post by:
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.