Download presentation
Presentation is loading. Please wait.
Published byDora Miles Modified over 6 years ago
1
MS Access VBA Programming Fundamental of Built-In Objects
2
The Application Object
The Application object contains all of the object that you create or use and that belong to the database you are working on. If you are planning to refer to the current database in your code, you can directly use the Application object. If you want to refer to a database other than the one that is currently opened, you should first declare an Application variable.
3
The Current Database When working in a Microsoft Access application, the database that is currently opened is identified as the CurrentDb object. This object is a child of the Application object. The CurrentDb object allows you to refer to the current database in your code.
4
The Current Project To identify the current project in your code, the Application object is equipped with a property called CurrentProject To refer to the current project, you can declare a variable of type Object and initialize it with the Application.CurrentProject object. This would be done as follows: Private Sub Detail_Click() Dim CurrentDatabase As Object Set CurrentDatabase = Application.CurrentProject txtFilename = CurrentDatabase.FullName End Sub
5
The Objects in the Current Database
While using an application, the objects that belong to the database are stored in a collection called CurrentData. The CurrentData object itself is a property of the Application object. To access the CurrentData object, you can first call the Application object, type the period operator, and type CurrentData. This would be done as follows: Application.CurrentData The CurrentData object holds the collections of objects that belong to the database.
6
The Objects in the Current Database
Application.CurrentData.AllTables(2).Name Private Function TableExists(ByVal tblName As String) As Boolean Dim obj As AccessObject, dbs As Object Set dbs = Application.CurrentData Dim exists As Boolean exists = False For Each obj In dbs.AllTables If obj.Name = tblName Then exists = True End If Next obj TableExists = exists End Function
7
An Access Object There are various types of objects you will use in your databases. Each object belongs to a particular collection. Still, to generally identify these various objects, each is identified as an AccessObject. This means that the AccessObject object is used to identify an object that belongs to a collection, whatever that object is and whatever its parent collection is.
8
Objects in MS Access: AllForms, AllReports, AllTables, AllModules, AllMacros, AllQueries Forms, Reports, Modules, Controls Form, Report, Module, Control …
10
The DoCmd Object This property is used to carry many of the actions you will need. An action performed on a database is also called a command. The methods of the DoCmd are: ddMenu ApplyFilter Beep CancelEvent Close CopyDatabaseFile CopyObject DeleteObject DoMenuItem Echo FindNext FindRecord GoToControl GoToPage GoToRecord Hourglass Maximize Minimize MoveSize OpenDataAccessPage OpenDiagram OpenForm OpenFunction OpenModule OpenQuery OpenReport OpenStoredProcedure OpenTable OpenView OutputTo PrintOut Quit Rename RepaintObject Requery Restore RunCommand RunMacro RunSQL Save SelectObject SendObject SetMenuItem SetWarnings ShowAllRecords ShowToolbar TransferDatabase TransferSpreadsheet TransferSQLDatabase TransferText
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.