Loop rst question - how to assign multiple criteria

H

hannes

Dear All,
I am trying to figure out how I can handle multiple criterias for a While
.... Wend loop (maybe a Do ... Loop While would be better?). I am creating a
query in VBA which shall return SQL statements which are stored in a table
called "test1" with the field name "Code".

The code looks like this with one criteria:

While (rst.EOF = False)
strSQL = strSQL & rst!
Code:
strSQL = strSQL & ", "
rst.MoveNext
Wend

Now I would like to have a second criteria for my While condition which I
could add with "And". Though my criteria is based on a field out of another
table called "test2" which is linked to table "test1" and which contains a
"field_ID" which acutally exist as primary key in table "test1". With a
normal SQL query I can query this, however I have no idea how to add this to
my VBA loop so I can restrict my inputs.... ???

Any help is deeply appreciated. Thanks
 
A

Alex Dybenko

Hi,
I think you can join both tables with field_ID in your rst and then make
loop like this


do until rst.EOF
if rst![a field of another table]=something then
exit do
end if
strSQL = strSQL & rst!
Code:
strSQL = strSQL & ", "
rst.MoveNext
loop


--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top