Step 2: Create a Data Environment Command Object

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 Phone table in the Employees sample 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 Phone table in the Employees sample database, set the following properties: Click to see How to Create a Command Object
Property Setting
Command Name EmployeesTable
Connection Connection1
Database Object Table
Object Name Phone

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. Click the + to the left of the EmployeesTable icon in the Data Environment designer window to see the fields in the Employees database.

Click to see Command Object Properties

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 EmployeesTable command, it also creates a Recordset object called "rsEmployeesTable."

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 EmployeesTable command in a data environment called "datEmployeesEnvironment," you can refer to the command in code as follows:

datEmployeesEnvironment.EmployeesTable

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

datEmployeesEnvironment.rsEmployeesTable

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.

Go to Step 3: