Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with For Each 2

Status
Not open for further replies.

jpl458

Technical User
Sep 30, 2009
337
US

Trying to run this simple code in Immediate window and keep getting Compile Error "Next without For".
Tried umpteen versions keep getting same error

For Each AccessObject In CurrentProject.AllForms
Debug.Print AccessObject.Name
Next
Or
For Each Control In Me.Controls
Debug.Print Control.Name
Next

Must be me, I'm sure.

Thanks in advance

jpl
 
Multi line/ statement code will only run in the immediate window if it is entered on one line;
So try entering;
For Each Control In Me.Controls: Debug.Print Control.Name: Next
 
Ran your sample on one line:
For Each Control In Me.Controls: Debug.Print Control.Name: Next
and got "Variable not created yet in this context"

Running Access Office 10
jpl
 
Is there a problem with running both blocks? If not just take out the For.

Code:
For Each AccessObject In CurrentProject.AllForms
  Debug.Print AccessObject.Name
Next

For Each Control In Me.Controls
 Debug.Print Control.Name
Next

If only one should be run then put nest it in an if statement

Code:
If 'enter critieria here' then
     For Each AccessObject In CurrentProject.AllForms
         Debug.Print AccessObject.Name
     Next
else
     For Each Control In Me.Controls
          Debug.Print Control.Name
     Next
endif
 
>and got "Variable not created yet in this context"
Means it will not run unless your project is running (but paused) in the IDE; i.e. a run context as opposed to a design context. Press F8 to start/ pause the project and try the one liner in the immediate window again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top