Using the Visual Data Manager

Using the Visual Data Manager

Using the Visual Data Manager

1. Load Visual Basic and select Standard EXE project

2. Go to the Add-in menu and run the Visual Data Manager (VisData). From the File menu select New, Microsoft Access, Version 7.0 MDB as shown below.

3. Right click on Properties in the Database Window and choose new table as shown below

4. The Table Structure Window opens. Enter the name "Customers" in the Table Name box at the top of the window. Click the Add Field Button and enter CustomerName in the name box, select Text in the type box and enter 40 in the size box. Check the Required box. Your entry should look like that below. Click OK so that another field can be added.

5. Add three more Fields as shown above. The next field should be named Postcode, be of type Text and of size 15. Do not check the required box. The following field should be named TelNumber, be of type Text and of size 30. Do not check the required box . Then add the field called Notes, make this of type Memo (selected from the drop down list). The size can not be selected with this type of field. Do not check the required box. Finally enter the last field and name it ID. Make it of type Long. Check both the required and AutoIncrField check boxes.

6. Click the Add Index button. Select ID from the Available Fields by clicking on it. Type ID into the name box. Ensure that both the Primary and Unique check boxes are ticked (see below). Press OK. Repeat but this time select CustomerName and enter CustomerName in the name box. Uncheck both the Primary and Unique check boxes and Press OK then Close.

7. Finally click the 'Build the Table' button at the bottom of the Table Structure Window. The database called Customers is created and is shown in the Database Window of VisData. The next step is to add data to the database.

8. Within the Visual Data Manager (VisData) click on both the Data Control and RecordSet Icons. Right click on the Customers database and select Open as shown below.

9. Enter some example data into the Fields as shown below. Click Update and Yes to save the new record. Add a few more records by clicking on the Add button which appears after entering the first record.

10. The database has now been created from within Visual Basic using the Visual Data Manager (in the last tutorial we used Access to build the database).

Definitions

Primary Key

The primary key is an indexed field such as ID whose values uniquely identify each record in the table.

Field type

Like variables, fields in a database table must have a data type. For example, the type Text is used for strings of characters with a maximum number of characters of 255. The type Long is used for whole numbers. The type Memo is used for strings of characters of up to 65,535 characters. Other types include Boolean (true/false), Currency (money values) and Date/Time.

Creating the user interface

11. The next step is to build a user interface so that we can add, delete and search for records. Select Form1 and place on it a Data Control as in the last tutorial. In the Properties Window select the DatabaseName property and using the navigator button (the three dots button which appears when this property is selected) select the database file we just created called customers.mdb. The select the RecordSource property and using the drop-down arrow select customers (i.e. the customers table).

12. Add four textboxes and four labels to create the form window (user interface) as shown below.

13. Select each textbox in turn and select the DataSource property to Data1. Then change the DataField property of each textbox to CustomerName, TelNumber, Postcode and Notes respectively.

14. Add three command buttons to the form and label them Add, Delete and Search respectively.

15. Double click on the Add command button and write the following code between the begin and end click procedure statements.

16. Double click the Delete button and write the following code.

17. Double click the search button and enter the following code.

18. Save and run the project (Start/Run or F5). You can now add, delete and search for records in the database. Example output is shown below.