Solved

Close if table is opened

Posted on 2011-09-23
5
255 Views
Last Modified: 2012-08-14

Dim td As TableDef
    For Each td In CurrentDb.TableDefs
        If td.Name = stLocalTableName Then
            CurrentDb.TableDefs.Delete stLocalTableName
        End If
    Next

Open in new window


Hi I have gotten the following code which is said to close the open tables only. But sometimes my tables get closed and I suspect this code!

Is this code actually deleting open tables?
Is there anyway to amend it to close a table if its open?
0
Comment
Question by:Shanan212
5 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 36587718
... code which is said to close the open tables only. But sometimes my tables get closed ...

??what??

This code is deleting a table whose name is in the variable stLocalTableName
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 250 total points
ID: 36587721
0
 
LVL 42

Accepted Solution

by:
dqmq earned 250 total points
ID: 36587936
That's stupid code.  It loops through all tabledefs and deletes at most one, regardless of whether it is open.  This code closes all tables:


   Dim td As TableDef
    For Each td In CurrentDb.TableDefs
          docmd.close actable, td.name
    Next
0
 
LVL 13

Assisted Solution

by:Shanan212
Shanan212 earned 0 total points
ID: 36587960
Thanks dgmg and I used this (as this checks if the table is open)

Sub closeObj()
Dim td As DAO.TableDef
For Each td In CurrentDb.TableDefs
    If IsOpen(td.Name, acTable) Then
        DoCmd.Close acTable, td.Name
    End If
Next
End Sub

Function IsOpen(strname As String, strtype As String) As Boolean
    If SysCmd(acSysCmdGetObjectState, strtype, strname) <> 0 Then
   
        IsOpen = True
   
    End If
End Function

0
 
LVL 13

Author Closing Comment

by:Shanan212
ID: 36715357
Found better solution via search
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now