Create a Data Environment Command Object

See Also

Once you've created a connection to your database, you can use the Data Environment designer to create Command objects that give you access to data. For example, you can create a simple Command object that gives you access to the data in a table, or a more complex Command object based on a query.

You can then use a data environment Command object as a data source in your application. First, you'll create a simple Command object based on the Customers table in the Northwind Traders sample database.

Note   This topic is part of a series that walks you through creating a simple database application that interacts with data in Nwind.mdb. It begins with the topic, Interacting with Data in a Microsoft Jet/Microsoft Access Database.

To create a simple data environment Command object

  1. Open a Data Environment designer.

  2. Create the Command object.

Open a Data Environment Designer

You can open an existing Data Environment designer or create a new one. To open an existing one, click Designers in the Project window, and then double-click the name of the designer. To create a new one, follow the instructions in the "Create a Connection to a Microsoft Access Database File" topic.

Create the Command Object

Create a data environment Command object by clicking the Add Command button on the Data Environment designer toolbar, or by right-clicking the connection in the data environment window and choosing Add Command from the menu. You can then specify the Command object's name, the connection it uses, and the source of its data in the Command Properties dialog box. To display this dialog box, right-click the Command object in your data environment and then choose Properties from the shortcut menu.

For example, to create a Command object based on the Customers table in the Northwind Traders sample database, set the following properties:

Property Setting
Command Name CustomersTable
Connection Connection1
Database Object Table
Object Name Customers

When you click OK, the Data Environment designer displays the Command object and its underlying fields in a hierarchical view in the Data Environment designer window.

The Data Environment designer also creates a Recordset object to represent the records returned by the Command object. The Recordset object uses the same name as the Command object but adds an "rs" prefix. For example, when the Data Environment designer creates the CustomersTable command, it also creates a Recordset object called "rsCustomersTable."

You can refer to the Command object in code as a method of the data environment, and refer to its recordset as a property of the data environment. For example, if you have created the CustomersTable command in a data environment called "MyDataEnvironment," you can refer to the command in code as follows:

MyDataEnvironment.CustomersTable

You can refer to the Command object's underlying recordset as follows:

MyDataEnvironment.rsCustomersTable

After you create the Command object, the Auto List Members feature and Object Browser display the command method and recordset property along with the other properties and methods of the data environment.

For More Information   See How Commands are Exposed for Programmatic Access.

Step by Step

This topic is part of a series that walks you through creating a simple database application that interacts with data in Nwind.mdb.

To See
Go to the next step Create a Simple Data-Bound Form
Start from the beginning Interacting with Data in a Microsoft Jet/Microsoft Access Database