For Each...Next Statement.

yeatmanj

Loose Cannon
Local time
Today, 15:49
Joined
Oct 11, 2000
Messages
195
I'm sorry to post this because I'm certain that there are a million threads about it. I just can't find them because the search function drops all the words except for Statement. That is an awful lot of results to go through, and when I'm working I just don't have that kind of time on my hands.

I have read all the MS BS about how to use a for each...next statement, but I don't understand it. I've read through some search results from the web. I still dont' understand it.

How does a for each...next statement work with a recordset. I've seen example "For each record in recordset", but if I'm using it do I really use the statements record and recordset? Shouldn't it be more like "For Each Item In MyRecordset"

Could someone please help me understand this?
 
Hello:

Basically this repeats a group of statements for each element in an array or collection. See the below example:
This loops through every form in your project and displays the name.

Sub AllForms()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllForms collection.
For Each obj In dbs.AllForms
'Display the name of obj.
Msgbox obj.Name
End If
Next obj
End Sub

Regards
Mark
 
I appreciate your input, but do you have an example that shows the proper syntax or way to reference a recordset object and have it perform the interations on a set of records. That is where my main confusion is. I have been unable to locate any information on how to use a for each statement with recordset syntax.
 
Why not use a Do.....Loop till MyRec.Eof
 
Do While not rs.EOF
operation 1
operation 2
rs.movenext
Loop
 

Users who are viewing this thread

Back
Top Bottom