Solved

How to consist this loop?

Posted on 2002-05-17
6
227 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 69
How does CurrentUser work? 10 38
IF ELSE Statement in Excel Macro VBA 16 75
Collapse and expand table in Word 2010 2 29
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

792 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