Working with Object Models

3 4

An object model is a representation of an application’s components, usually in a hierarchical structure, showing the relationships between the application’s objects. When you write VBA code to add functionality to an application, you’re primarily working with the Access object model, which represents most of the components you work with in the Access interface, such as forms, reports, and controls. The Access object model gives you control over a great many settings and actions via methods such as the RunCommand method of the DoCmd object. To work with data, however, your application will need to use other object models, such as the Data Access Objects (DAO) object model or the ActiveX Data Objects (ADO) object model.

Properties, Methods, and Events

The objects in an object model might have properties, methods, and events. (Not all objects have all three.) Properties are attributes of an object, such as the Height or Width properties of a text box control. Methods are actions that can be performed using the object, such as the Open method to open a form. (Some people like to think of properties as adjectives and methods as verbs.) Events are things that happen to objects, such as clicking a command button or printing a report, that can be used to trigger actions using event procedures.

Access Object Model

The Access object model represents the Access interface—forms, reports, controls, data access pages, and other Access components. It also has the DoCmd object, whose RunCommand method is used to run a large number of commands that correspond to actions you can take in the interface. Figure 20-3 shows a high-level view of the Access object model.

figure 20-3. a high-level view of the access object model shows only the main access objects.

Figure 20-3. A high-level view of the Access object model shows only the main Access objects.

You can view a more detailed diagram of the Access object model in the Access Help facility. To start Access Help, choose Help, Microsoft Access Help. In the left pane of the Access Help window, click the Contents tab to display a list of Help categories (called Help books). To view the Access object model diagram, open the Programming in Visual Basic Reference Help book, and then the Microsoft Access Visual Basic Reference book under it, and select the Microsoft Access Object Model Help topic.

DAO Object Model

The DAO object model has grown up with Access and is still the best object model for working with Access data (as opposed to interface elements such as forms and reports). You can use the DAO object model to work with data in Access tables and to create and manipulate tables and queries programmatically. It also has components you can use to manage security for an Access database. Figure 20-4 shows a high-level view of the DAO object model.

To view the full DAO object model, open the Microsoft Data Access Objects 3.60 (DAO) Help book, and then the Microsoft DAO 3.60 book under it, and then the DAO Objects Reference book under that, and then the DAO Object Model for Microsoft Jet Workspaces Help topic.

figure 20-4. a high-level view of the dao object model shows the main objects only.

Figure 20-4. A high-level view of the DAO object model shows the main objects only.

ADO Object Model

The ADO object model is the new kid on the block. It has only a few objects and thus has less functionality than the DAO object model for working with Access databases and their data. Unlike with DAO, however, you can use the ADO object model to work with non-Access data (such as SQL Server data or ODBC data sources). If you need to work with data in other formats, you need ADO. Figure 20-5 shows the ADO object model; notice that the objects aren’t arranged hierarchically.

figure 20-5. the ado object model isn’t hierarchical.

Figure 20-5. The ADO object model isn’t hierarchical.

To view the ADO object model in Help, open the Microsoft ActiveX Data Objects (ADO) Help book, and then the Microsoft ADO Programmer’s Reference book under it, and then ADO API Reference book under that, and then the ADO Object Model Help topic.



Microsoft Access Version 2002 Inside Out
Microsoft Access Version 2002 Inside Out (Inside Out (Microsoft))
ISBN: 0735612838
EAN: 2147483647
Year: 2005
Pages: 172
Authors: Helen Feddema

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net