When you work with data in a Microsoft Access database, you must first create a connection to a database file. The easiest way to create a connection to a Microsoft Access file is to create a data environment using the Data Environment designer.
This topic shows how to create a connection to the Phone List sample database (Employees.mdb). It assumes that the database file is located on the Student Disk downloaded from the publisher site by using the back cover of the text.
To create a connection to a Microsoft Jet/Microsoft Access database file
A Data Environment designer provides an easy way to create connections to many types of databases. To add a designer to your project, click Add Data Environment on the Project menu. Visual Basic loads a data environment and adds a Connection object to the data environment. Click the DataEnvironment1 icon in the Data Environment Window, change its name property in the property window to datEmployeesEnvironment and press Enter key.
If the Data Environment designer is not available on the Project menu, add it to your Visual Basic environment. Click Components on the Project menu, click the Designers tab, and then click the check box next to its name in the list of designers. |
![]() |
Note The first four kinds of ActiveX designers loaded for a project are listed on the Project menu. If more than four designers are loaded, the later ones will be available from the More ActiveX Designers submenu on the Project menu.
You establish the connection to your data source by setting properties in the Data Link Properties dialog box. To display this dialog box, right-click the Connection object in your data environment and then choose Properties from the shortcut menu. Select an OLE DB provider on the Provider tab of the dialog box. Then click Next and enter connection information on the Connection tab of the dialog box. The layout of the Connection tab varies, depending on the OLE DB provider you select on the Provider tab. |
![]() |
For example, to connect to a Microsoft Jet/Microsoft Access database such as the Employees sample database, select the Microsoft Jet 3.51 OLE DB provider on the Provider tab. On the Connection tab, enter the path to the database file; for example: