How to Nest For, Do Until loop?

D

deko

This code does not compile - the error rec'd says "Next without For"

For Each olmi In olfsm.Items
rstS.MoveFirst
Do Until rstS.EOF
If Not IsNull(rst!strS) Then 'I want to check each item in
recordset that is not null
If (InStr(olmi.To, rst!srtS)) > 0 Then
rst.AddNew
rst!DateSent = olmi.SentOn
rst!Subject = olmi.Subject
rst!Recipient = olmi.To
rst.Update
End If
End If
rstS.MoveNext
Next

where am I going wrong? Is it possible to nest a Do Until inside a For
loop?
 
K

Ken Slovak - [MVP - Outlook]

Yes, but you need some terminating statement for your Do loop:

rstS.MoveNext
Loop
Next
 
B

Brian Tillman

deko said:
This code does not compile - the error rec'd says "Next without For"

For Each olmi In olfsm.Items <----------------------------+
rstS.MoveFirst |
Do Until rstS.EOF |
If Not IsNull(rst!strS) Then 'I want to check each item |
in recordset that is not null <-----------------+ |
If (InStr(olmi.To, rst!srtS)) > 0 Then <----+ | |
rst.AddNew | | |
rst!DateSent = olmi.SentOn | | |
rst!Subject = olmi.Subject | | |
rst!Recipient = olmi.To | | |
rst.Update | | |
End If <-----+ | |
End If <-----------------+ |
rstS.MoveNext |
<----------------------------+

where am I going wrong?

It appears as though you do not have the ending indicator for the Do Until.
--
Brian Tillman
Smiths Aerospace
3290 Patterson Ave. SE, MS 1B3
Grand Rapids, MI 49512-1991
Brian.Tillman is the name, smiths-aerospace.com is the domain.

I don't speak for Smiths, and Smiths doesn't speak for me.
 

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