Rambler's Top100
Российский фонд помощи
Навигация
Главная
MS ACCESS
VB
ASP
PHP
Наши друзья
Поиск
Форум
Лента новостей
Новый сайт

Online
Рассылки Subscribe.Ru
Работа с MS Access
Подписаться письмом
Реклама на сайте
 
Главная arrow MS ACCESS arrow Закрыть все открытые таблицы
Закрыть все открытые таблицы Печать E-mail
Автор Daniel Pineault   
27.04.2023 г.
Вам когда-нибудь приходилось закрывать все открытые таблицы? Убеждаться, что ни одна таблица еще не открыта?


'---------------------------------------------------------------------------------------
' Procedure : CloseAllOpenTables
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Close all the currently open Tables in the database
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
' (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: None required
'
' Usage:
' ~~~~~~

' ? CloseAllOpenTables

' Returns -> True => Closed all Tables successfully
' False => A problem occurred
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2015-02-17 Initial Release
' 2 2023-02-09 Update variable naming, Error handler, copyright
'---------------------------------------------------------------------------------------
Function CloseAllOpenTables() As Boolean
On Error GoTo Error_Handler
Dim oTbls As Object
Dim oTbl As Access.AccessObject

Set oTbls = CurrentData.AllTables

For Each oTbl In oTbls 'Loop all the tables
If oTbl.IsLoaded = True Then 'check if it is open
DoCmd.Close acTable, oTbl.Name, acSaveNo
End If
Next oTbl

CloseAllOpenTables = True

Error_Handler_Exit:
On Error Resume Next
Set oTbl = Nothing
Set oTbls = Nothing
Exit Function

Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Source: CloseAllOpenTables" & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"

Resume Error_Handler_Exit
End
Function
Код очень прост. Он просто перебирает все таблицы базы данных (CurrentData.AllTables), проверяет, загружена ли таблица в данный момент (IsLoaded), и если да, то закрывает ее (DoCmd.Close) без сохранения изменений в структуре таблицы..

Примеры использования
Затем, чтобы использовать функцию, мы просто делаем:
Call CloseAllOpenTables
Или

If CloseAllOpenTables = True Then 
'...
End
If


Источник
Access – VBA – Close All Open Tables

Просмотров: 353

  Ваш коментарий будет первым

Добавить коментарий
Имя:
E-mail
Коментарий:



Код:* Code

 
Реклама на сайте
HiProg.com - Технологии программирования
Rambler's Top100 TopList