Solved

How to consist this loop?

Posted on 2002-05-17
6
226 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

785 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