Каталог статей
Иногда бывает надо получить список присутствующих в базе элементов. Причины могут быть самые разные. Самое простое - пройтись циклом по соответствующим семействам. И так, приступим.
Sub AllTables()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllTables collection.
For Each obj In dbs.AllTables
' Print name of obj.
Debug.Print obj.Name
Next obj
End Sub
Sub UserTables()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllTables collection.
For Each obj In dbs.AllTables
If Left(obj.Name, 4) <> "MSys" Then
If Left(obj.Name, 1) <> "~" Then
' Print name of obj.
Debug.Print obj.Name
end if
End If
Next obj
End Sub
Sub OpenTables()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllTables collection.
For Each obj In dbs.AllTables
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name
End If
Next obj
End Sub
Sub OpenTables()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllTables collection.
For Each obj In dbs.AllTables
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name, obj.CurrentView
' CurrentView = 0 as acCurViewDesign
' CurrentView = 2 as acCurViewDatasheet
End If
Next obj
End Sub
Список таблиц можно получить и вот так, через DAO
Sub AllTablesDAO()
Dim dbs As Database, tdf As TableDef
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
' Print name of obj.
Debug.Print tdf.Name
Next tdf
Set tdf = Nothing
dbs.Close
Set dbs = Nothing
End Sub
Теперь перейдём к запросам.
Sub AllQueries()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllQueries collection.
For Each obj In dbs.AllQueries
' Print name of obj.
Debug.Print obj.Name
Next obj
End Sub
Sub OpenQueries()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllQueries collection.
For Each obj In dbs.AllQueries
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name, obj.CurrentView
' CurrentView = 0 as acCurViewDesign
' CurrentView = 2 as acCurViewDatasheet
End If
Next obj
End Sub
Sub AllForms1()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllForms collection.
For Each obj In dbs.AllForms
' Print name of obj.
Debug.Print obj.Name
Next obj
End Sub
Sub OpenForms()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllForms collection.
For Each obj In dbs.AllForms
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name, obj.CurrentView
' CurrentView = 0 as acCurViewDesign
' CurrentView = 1 as acCurViewFormBrowse
' CurrentView = 2 as acCurViewDatasheet
' CurrentView = 3 as acCurViewPivotTable
End If
Next obj
End Sub
Sub AllReports()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllReports collection.
For Each obj In dbs.AllReports
' Print name of obj.
Debug.Print obj.Name
Next obj
End Sub
Sub OpenReports()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllReports collection.
For Each obj In dbs.AllReports
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name, obj.CurrentView
' CurrentView = 0 as acCurViewDesign
' CurrentView = 5 as acCurViewPreView
' CurrentView = 6 as acCurViewReportBrowse
' CurrentView = 7 as acCurViewLayout
End If
Next obj
End Sub
Sub AllMacros()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllMacros collection.
For Each obj In dbs.AllMacros
' Print name of obj.
Debug.Print obj.Name
Next obj
End Sub
Sub OpenMacros()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllMacros collection.
For Each obj In dbs.AllMacros
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name, obj.CurrentView
' CurrentView = 0 as acCurViewDesign
End If
Next obj
End Sub
Sub AllModules()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllTables collection.
For Each obj In dbs.AllModules
' Print name of obj.
Debug.Print obj.Name
Next obj
End Sub
Sub OpenModules()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllModules collection.
For Each obj In dbs.AllModules
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name, obj.CurrentView
' CurrentView = 0 as acCurViewDesign
End If
Next obj
End Sub
| |
Просмотров: 189 | | |
Всего комментариев: 0 | |