Doing a ad hoc loop in Immediate Window (1 Viewer)

Status
Not open for further replies.

Banana

split with a cherry atop.
Local time
Today, 11:40
Joined
Sep 1, 2005
Messages
6,315
Sometime I want to get a list of fields of a recordset or table or maybe iterate over the collection in middle of development and I really don't want to go over to table, open it, or run a query or even write a temporary sub just to house the code.

Thus I came to do this out of habit using Immediate Window to give me the list for my development use.

Suppose I forgot what field name I was looking for or wanted to verify the spelling from a table. In the immediate window, we cannot write more than line of code- it doesn't work the same work. However, we can use colon instead of newline to separate statements. So instead of this code snippet:

Code:
For Each v In CurrentDb.TableDefs("MyTable").Fields
   Debug.Print v.Name
Next

The Immediate window would be one long line of same statement delimited by colons:
Code:
for each v in currentdb.tabledefs("mytable").fields:debug.print v.name:next

Note that we also don't need to do a Dim variable when working inside the immediate window, which saves us from typing a dim statement had we had to write a temporary sub that would be immediately deleted right after we're done.

It should of course go without saying that if we tried to do the same thing in the actual code, be prepare to weep when you have to go back and read it. There's a reason for a newline and tabs.

Hope this helps others. :)
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom