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

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.
LVL 11
TravisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jerryb30Commented:
Any table? What do you mean by 'opened manually'?
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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

mx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
omgangIT ManagerCommented:
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
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Note that the acSavePrompt is referring to Design changes, not data changes - which would probably get saved when the table closes anyway.

mx
0
omgangIT ManagerCommented:
mx is correct, the acSaveYes pertains to design changes.
OM Gang
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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 ...
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
good one omg ... forgot about SysCmd !

mx
0
TravisAuthor Commented:
thanks for the quick answers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.