Looping Thru Tables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
Back
Top