Visual Basic and Active Database Object
Tutorial with Examples
- To connect to a database and table:
- Add a Data Object which looks like this:

- Works like a CD player with first record, previous record, next record, and last record
- Change the (Name) property to identify the table
- Change the DatabaseName property to select the database
- Change the RecordSource property to select the table
- To connect a field to an object:
- Add Textbox Objects for each field in the table
- Change the (Name) property to identify the field
- Change the DataSource property to select the table
- Change the DataField property to select the field
- The data in the fields will show in the Textbox Objects
- Use the Data Object controls to move around in the database
- To display the records of a database on a listbox:
- Create a Listbox Object
- Clear the Listbox Object
- Use datTableName.Recordset.MoveFirst to move to the first record
- Use datTableName.Recordset.EOF in a loop to test for end of file
- Use datTableName.Recordset!fieldName to display the contents of a field
- Build a string variable one field at a time and then display add to a Listbox Object
- To search for a particular record in the database:
- Declare a string variable
- Assign an SQL SELECT command to the string variable
- Move to the first record in the dataset
- Use datTableName.Recordset.FindFirst strVar to search for the first matching record
- The first match will display in your Textbox Objects
- To search for multiple occurances of matching records:
- Loop while not EOF
- Add any matching records to a Listbox Object
- If datTableName.Recordset.NoMatch then MoveLast and MoveNext to force an EOF
- Add records:
- Create a form with enough textboxes for every field in the table
- Add a Data Object, set the DataBaseName, set the RecordSource
- Add a Command Button Object
- Use datTableName.Recordset.AddNew
- Use datTableName.Recordset!fieldName = txtTextBoxName.Text to add data to each field
- When all fields have been data added, use datTableName.Recordset.Update to update the record and close the add new
- Change records:
- Allow the user to change the data displayed on the form
- Delete records:
- Display the correct record
- Use datTableName.Recordset.Delete
- Be sure to confirm the deletion with the user to allow the user to change her mind
-
-
-
-
-