Is it possible to attach a command to the closing of a query or table. My simple access database needs to stay simple, since I am. So I don't want to create a lot of forms that can complete VBA commands when closing. So what I want to do is restore the Switchboard form when tables or query's are closed. Is this possible?
Can I DoCmd attached to a query or table?
Collapse
X
-
I guess there is no simple way to do it.Is it possible to attach a command to the closing of a query or table. My simple access database needs to stay simple, since I am. So I don't want to create a lot of forms that can complete VBA commands when closing. So what I want to do is restore the Switchboard form when tables or query's are closed. Is this possible?
A quite complicated way is to poll AllTables and AllQueries collection to check whether some table or query was opened/closed.
[/code]Code:Private Sub Form_Load() Me.TimerInterval = 10 End Sub Private Sub Form_Timer() Dim obj As AccessObject IterateAccessObjectsCollection CurrentData.AllTables IterateAccessObjectsCollection CurrentData.AllQueries For Each obj In colLoadedAccessObjects If Not obj.IsLoaded Then MsgBox obj.Name & " has been closed" colLoadedAccessObjects.Remove obj.Name End If Next End Sub Private Sub IterateAccessObjectsCollection(objCol As Object) Dim obj1 As AccessObject, obj2 As AccessObject Dim blnMatch As Boolean For Each obj1 In objCol If obj1.IsLoaded Then For Each obj2 In colLoadedAccessObjects If obj1.Type = obj2.Type And obj1.Name = obj2.Name Then blnMatch = True Next If Not blnMatch Then colLoadedAccessObjects.Add obj1, obj1.Name MsgBox obj1.Name & " has been opened" End If End If Next End Sub
Comment