Determine if table is open in VBA and if open close that table saving changes

Posted on 2008-11-19
Medium Priority
Last Modified: 2012-05-05
In Access 2003 VBA, I would like to determine if a table has been opened manually, if it has been opened I would like to save the table and close it all via VBA.
Question by:thydzik
LVL 26

Expert Comment

ID: 22999905
Any table? What do you mean by 'opened manually'?
LVL 75

Accepted Solution

DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1000 total points
ID: 22999926
I am not aware of any way to tell if a table has been opened 'manually' - if you mean say be a user ?

But you could close any open tables like so:

docmd.Close acTable,"Table1",acSavePrompt

LVL 28

Assisted Solution

omgang earned 1000 total points
ID: 22999958
Function isOpen(strName As String, intObjectType As Integer) As Integer
'checks to see if the database object passed is open or not
'returns true if object is open
    isOpen = (SysCmd(SYSCMD_GETOBJECTSTATE, intObjectType, strName) <> 0)
End Function

Public Function CloseObject(strName As String)

    DoCmd.Close acTable, strName, acSaveYes
End Function

Object types
acTable  0  
acQuery  1  
acForm  2  
acReport  3  
acMacro  4  
acModule  5  
acDataAccessPage  6  

OM Gang
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

LVL 75
ID: 22999959
Note that the acSavePrompt is referring to Design changes, not data changes - which would probably get saved when the table closes anyway.

LVL 28

Expert Comment

ID: 22999974
mx is correct, the acSaveYes pertains to design changes.
OM Gang
LVL 85
ID: 23000006
I would suggest that, if your users can directly access your tables, then the least of your worries would be whether a table is "manually open" or not ...
LVL 75
ID: 23000015
good one omg ... forgot about SysCmd !

LVL 11

Author Closing Comment

ID: 31518529
thanks for the quick answers

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question