A Visual Basic Address Book Database

In this page, we are going to create a simple address book database for personal and business contacts. The names and addresses will come from a Microsoft Access database (Contacts.accdb) which you can download from the link below. We will be using the wizards provided by Visual Basic to do most of the work, which means that there is relatively little programming required.

Download the Contacts.accdb database here

Important: In order for the application to work correctly, make sure you have SQL Server Express 2016 LocalDB installed on your computer (if not, you can run the Visual Studio installation application once more and modify your installation to include this component).

The technology used to interact with the Access database is Microsoft's ActiveX Data Objects (ADO). The ADO Base Class includes five major objects:


Using the Data Source Configuration wizard

We will use the Data Source Configuration wizard to create a program that reads the Contacts.accdb database and allows us to scroll through it and add to or edit its contents. The exercise demonstrates that you do not have to write any code or understand the precise way in which Visual Basic interacts with the database in order to create a simple database application.

  1. Open a new project and name it "AddressBook".
  2. Save the project immediately to create the project folder.
  3. If you have not already done so, download the Contacts.accdb database. Copy or save it to the \bin\Debug subdirectory of your your project folder.
  4. Select Project Add New Data Source.... You should see the following screen:

The Data Source Configuration wizard

The Data Source Configuration wizard


  1. Make sure "Database" is selected, and click the Next button. You should see the following screen:

You will be asked to choose a database model

You will be asked to choose a database model


  1. Make sure the Dataset option is selected (as you can see from the illustration above, this may well be the only option available to you), and click the Next button. You should see the following screen:

The wizard allows us to choose a data connection

The wizard allows us to choose a data connection


  1. Click on the New Connection... button to bring up the following dialog box:

This dialog box allows us to choose a datasource type

This dialog box allows us to choose a datasource type


  1. Make sure "Microsoft Access Database File" is selected and click on the Continue button. You will see another dialog boy like the one illustrated below.

This dialog box allows us to choose a database

This dialog box allows us to choose a database


  1. Click on the Browse button, navigate to your project folder's \bin\Debug directory, and select the Access database file Contacts.accdb. You should now see the filename and path for the database appear in the dialogue box:

You should now see the filename and path for the database in the dialogue box

You should now see the filename and path for the database in the dialogue box


  1. Click on the Test Connection button to verify that the connection works*. You should see a meessage telling you that the test has succeeded. Click on OK.

You should see a message telling you the test has succeeded

You should see a message telling you the test has succeeded.




* If you recieve a message saying "Unrecognised database format", you may need to download and install the file AccessDatabaseEngine, and restart Visual Studio.

  1. Click on OK once more. You should now see the name of the database in the Data Source Configuration wizard.

You should now see the name of the database in the Data Source Configuration wizard

You should now see the name of the database in the Data Source Configuration wizard


  1. Click on the Next button. You will see the following message:

Copy the database file to your project

Copy the database file to your project


  1. Click Yes (the database file will be copied to your project folder). The Data Source Configuration wizard will now look like the illustration below.

You should see the default name for the connection string

You should see the default name for the connection string


  1. Click on the Next button. The Data Source Configuration wizard will now look like the illustration below.

You can select the objects you want to be in the dataset

You can select the objects you want to be in the dataset


  1. Click on the right-facing arrow () next to the Tables checkbox to expand the view, and click the checkbox itself. You should see that the Contact table is now selected. Click on the right-facing arrow next to the Contact table checkbox to expand the view once more. You should see that all of the table's fields have been selected.

All of the fields in the Contact table are selected

All of the fields in the Contact table are selected


  1. Click on the Finish button. Open the Data Sources pane by clicking on the Data Sources tab on the left hand side of the Visual Studio window (if the tab is not visible, click View Other Windows Data Sources). The Data Sources pane should now display information about the database, as shown below.

The Data Sources pane

The Data Sources pane


  1. In the Data Sources pane, click the arrow () next to Contact to see the available fields:

Expand the list to see the available data fields

Expand the list to see the available data fields



Creating the form

We will now create the form controls that will allow us to look at the information in the database (if the Data Sources pane is not currently open, open it up again now).

  1. To add the FirstName field to the form, click on it in the list and drag it onto the form. This action not only creates a text box with a label, it also places a set of navigation controls at the top of the form, as shown below (note: if the Data Sources pane covers up the form when you open it, you can drag it into a different position or toggle its Auto Hide property until you are able to see both the form and the Data Sources pane).

We have added a field (and some navigational controls) to the form

We have added a field (and some navigational controls) to the form


  1. Some other, unfamiliar objects appear at the bottom of the form design window (we will discuss how these are used elsewhere). For now, run the program and use the navigation controls to scroll through the databaseto get a feel for how they work, then close the application return to the form design window.
  1. Drag the remaining fields onto the form (except for the ID field). Move them around and resize them until you are satisfied with the layout (you may have to make the form bigger to fit all the fields in). Your form should now look (something) like this:

The form elements are all (approximately) in place

The form elements are all (approximately) in place


  1. Run the application again and use the navigation controls to test it. Your form should now be displaying all of the information in the database, and have the required basic functionality. You can probably think of a few cosmetic changes that would make the inteface look a little more professional.

The basic application is now ready for use

The basic application is now ready for use