closing all tables

  • Thread starter Thread starter sverre
  • Start date Start date
S

sverre

Hi


I have written a function to close a table called SESAM.
How do I re-write the function to make all tables to close ?

Thank you in advance!

Function CLOSESESAM()
DoCmd.Close acTable, "SESAM", acSaveYes
End Function
 
There is probably a better way, but this one seemed to work:

Function CloseOpenTables()
Dim db As dao.Database
Dim td As dao.TableDef
Set db = CurrentDb
For Each td In db.TableDefs
DoCmd.SelectObject acTable, , True
DoCmd.Close acTable, td.Name, acSaveYes
Next
Set td = Nothing

End Function
 
Hi Ralph, and thanks for the tip. I ran the function on my mdb (which is
Acess 2002)
and it got stuck on the first line

Dim db As dao.Database

Error message says that "own defined type has not been defined"

I suspect that this error relates to Access 2002. For example I wasnt able
to get help on "dao" in the help function.

Do you have any suggestions on how I solve this?
Regards

Sverre
I
 
In the Module choose Tools from the Menu bar then References. Scroll down
until you find 'Microsoft DAO 3.6 Object Library' then select it.
 
Thanks Ralph, works perfect!
Sverre

Ralph said:
In the Module choose Tools from the Menu bar then References. Scroll down
until you find 'Microsoft DAO 3.6 Object Library' then select it.
 
Hi again Ralph,

Now I noticed that users open queries and reports in my mdb which also locks
my import. Could you help me with a similar code to automatically close all
reports and queries aswell?

Or at least give me a clue of what parts in your code to change to close
reports and queries instead of tables.

Many thanks in advance.
Sverre
 
Back
Top