Looping Thru Tables

R

Ross

How do I convert this code to loop thru tables (instead of forms)?

Sub CloseForms()
For Each frm In Application.Forms
If frm.Caption <> Screen. ActiveForm.Caption Then frm.Close
Next
End Sub

Thanks,

Ross
 
R

Rosco

Try This

Function LoopThruTables()
Dim db as Database, tdf as TableDef

Set db= CurrentDb
For Each tdf in db.TableDefs
( Code to execute what ever)
Next
End Function

You could also vinclude this code in a Sub routine
Rosco
 
A

Allen Browne

The code does not convert simply, as there is no Tables collection like the
Forms collection.

You could:
- get a list of the tables from the TableDefs collection,
- use the function below to see if it is open, and if so,
- close it with DoCmd.Close

Function IsLoaded(strName As String, _
Optional ObjType As AcObjectType = acForm) As Boolean
' Returns True if the specified object is open.
IsLoaded = (SysCmd(acSysCmdGetObjectState, ObjType, strName) <> 0)
End Function
 

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