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, you will need to install SQL Server Express 2019 LocalDB (assuming you have not already done so). To do this, proceed as follows:

  1. Run the Visual Studio Installer application once more. You should see the following screen:

The Visual Studio Installer screen

The Visual Studio Installer screen


  1. Click the Modify button. On the screen that appears (see below), the .Net desktop development option should be selected. Under "Installation details", check the box next to the SQL Server Express 2019 LocalDB option (you may need to scroll down the list to see it), and then click the Modify button. The required component will now be downloaded and installed. Once this process is complete, you can close the installer.

Check the SQL Server Express 2019 LocalDB option and click on the modify button

Check the SQL Server Express 2019 LocalDB option and click on the modify button


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, but this time select Widows Forms App (.Net Framework) from the Create a new project window, as per the illustration below (you may have to scroll down through quite a few options before you find it). Name your project "AddressBook".

Select the Widows Forms App (.Net Framework) option

Select the Widows Forms App (.Net Framework) option


  1. Save the project immediately to create the project folder.
  2. If you have not already done so, download the Contacts.accdb database. Copy or save it to the \bin\Debug\ sub-directory of your project folder.
  3. 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 the datasource type and database

This dialog box allows us to choose the datasourcee type and database


  1. Make sure "Microsoft Access Database File" is selected, then click on the Browse button.
  2. 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 AccessDatabaseEngine.exe, 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.

Note: You may get the error message "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine". If so, download and install AccessDatabaseEngine.exe, and restart Visual Studio.

  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, and resize the form if required. 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