Solved

Close if table is opened

Posted on 2011-09-23
5
242 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
Comment Utility
... 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
Comment Utility
0
 
LVL 42

Accepted Solution

by:
dqmq earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Found better solution via search
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

772 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

10 Experts available now in Live!

Get 1:1 Help Now