Microsoft Access VBA Macro Programming

(Tina Sui) #1
You can now add the following code into a module:

Sub Inventory()
Dim Obj As AccessObject, Dbs As Object, RecSet As Recordset
CurrentDb.Execute "delete * from tblObjectInventory"
Set RecSet = CurrentDb.OpenRecordset("tblObjectInventory")

Set Dbs = Application.CurrentData

For Each Obj In Dbs.AllTables
RecSet.AddNew
RecSet!ObjectName = Obj.Name
RecSet!ObjectType = "Table"
RecSet!DateCreated = Obj.DateCreated
RecSet!DateModified = Obj.DateModified
RecSet.Update

Next Obj

For Each Obj In Dbs.AllQueries
RecSet.AddNew
RecSet!ObjectName = Obj.Name
RecSet!ObjectType = "Query"
RecSet!DateCreated = Obj.DateCreated
RecSet!DateModified = Obj.DateModified
RecSet.Update

Next Obj
For Each Obj In CurrentProject.AllForms
RecSet.AddNew
RecSet!ObjectName = Obj.Name
RecSet!ObjectType = "Form"
RecSet!DateCreated = Obj.DateCreated
RecSet!DateModified = Obj.DateModified
RecSet.Update

Next Obj
For Each Obj In CurrentProject.AllReports
RecSet.AddNew
RecSet!ObjectName = Obj.Name
RecSet!ObjectType = "Report"
RecSet!DateCreated = Obj.DateCreated
RecSet!DateModified = Obj.DateModified
RecSet.Update

318 Microsoft Access 2010 VBA Macro Programming

Free download pdf