Solved

How to consist this loop?

Posted on 2002-05-17
6
221 Views
Last Modified: 2010-05-02
Hi,

In my project, I have 2 Access 97 tables (T1 & T2), every one contains only 5 records and one field “F1”. Please I need the LOOP Code which makes me fill “F1” in the record (1) of “T1” by the world “RED” THEN fill “F1” in the record (1) of “T2” by the same world  … Then fill “F1” in the record (2) of “T1” by the same world  THEN  fill “F1” in the record (2) of “T2” by the same world  … and so on till the EOF  (I mean going between the 2 tables once here and the other there …..till EOF)
Sirs, I know how to use ADO and how to fill the records. I want your help to show me the LOOP code which makes my request mentioned above.  

ray14
0
Comment
Question by:ray14
6 Comments
 
LVL 1

Accepted Solution

by:
hiranmaya earned 50 total points
ID: 7016706
try this!!!

alltrue = false
RED = true
BLUE = true

Do until
'open T1
.movefirst
If T1EOF is false
if RED =true
'update F1 with Red
RED = false
BLUE = true
elseif BLUE = true
'update F1 with blue
BLUE false
RED =true
end if
.movenext if not eof
else
T1EOF is true    
end if

'open T2
.movefirst
If T2EOF is false
if RED =true
'update F1 with Red
RED = false
BLUE = true
elseif BLUE = true
'update F1 with blue
BLUE false
RED =true
end if
.movenext if not eof
else
T2EOF is true
end if

If T1EOF is true and T2EOF is true then
alltrue = true
endif    
loop alltrue = true


tx in adv.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 7016708
'Setup RS1 for T1 and RS2 for T2

RS1.movefirst
RS2.movefirst

do while not RS1.eof
  rs1!F1 = "RED"
  rs1.update
  rs1.movenext
  rs2!F1 = "BLUE"
  rs2.update
  rs2.movenext
loop

'CLOSE THE RECORDSETS

If you know you have 5 records you can use a FOR loop instead

The above assumes T2 has at least as many records as T1
   
mlmcc
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7016711
why do you need to loop?

why not just do,

conn.execute "Update T1 set F1 = 'Red'"
conn.execute "Update T2 set F1 = 'Blue'"

where conn is your adodb.connection?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:ray14
ID: 7016739

0
 
LVL 100

Expert Comment

by:mlmcc
ID: 7019246
bobbit31

WIll tht update all records?

mlmcc
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7021576
> WIll tht update all records?

it should
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now