for each loop...I think (1 Viewer)

token_remedie

Registered User.
Local time
Today, 17:39
Joined
Jul 7, 2011
Messages
78
is it possible to do something like this?

for each record in a table
if table1.field = table2.field then update table1.field2 = yes
else next record

I've been looking through the MS help and it doesn't really tell me much, using access 2010

if so, how would I go about doing this?
Thank you
 

vbaInet

AWF VIP
Local time
Today, 08:39
Joined
Jan 22, 2010
Messages
26,374
Why not just do it in a query?
Code:
IIF([Field1] = [Field2], "Yes", Null)
You shouldn't storing this value.
 

token_remedie

Registered User.
Local time
Today, 17:39
Joined
Jul 7, 2011
Messages
78
Why not just do it in a query?
Code:
IIF([Field1] = [Field2], "Yes", Null)
You shouldn't storing this value.

just keeps saying expected =

so I was thinking something like this:

Code:
   If (DoCmd.RunSQL("SELECT master.[asset number], desttable.[asset number] FROM master, desttable WHERE master.[asset number] = desttable.[asset number];")) Then
   DoCmd.RunSQL ("UPDATE master.[destroyed] = Yes;")

but that isn't working either :( says argument not optional
 

vbaInet

AWF VIP
Local time
Today, 08:39
Joined
Jan 22, 2010
Messages
26,374
Like I previously mentioned, you should not be storing calculated values. The IIF() statement shhould go in a new column in your SELECT query (not UPDATE query).
 

Users who are viewing this thread

Top Bottom