DAO 3.6 Library

A Worked Example

So now you have a wonderful library that helps you to add, edit and delete records. You've written a Default Database module too that links the library with your Access database. But how does it all tie together?

Below, I'll show you the code that will add two records to the people table, edit their fields and then delete one of the records. See if you can figure out how to do the same to the animals table. For now, you can just stick this in your Form_Load procedure. It may be useful to use the debugging tools to step through the code and see exactly what is going on.

Dim strPath as String
Dim intNewRecord As Integer
Dim intReturn As Integer
Dim intRecordToDelete As Integer

strPath = "C:\My Documents\Test.mdb"
LoadDatabase strPath

intNewRecord = AddNewRecord(rstPeople)

intReturn = ChangeField(rstPeople, intNewRecord, "FirstName", "Louis")
intReturn = ChangeField(rstPeople, intNewRecord, "LastName", "Rose")
intRecordToDelete = intNewRecord

intNewRecord = AddNewRecord(rstPeople)
intReturn = ChangeField(rstPeople, intNewRecord, "FirstName", "Laura")
intReturn = ChangeField(rstPeople, intNewRecord, "LastName", "Hickson")

intReturn = DeleteRecord(rstPeople, intRecordToDelete)


If you check your database in Access now, you'll see that VB has added one person to the People database and the values of the fields (from left to right) will be: 2, Laura, Hickson

In fact, we added me to the database too, but then promptly deleted me. (Humph!)

I hope this library will give you some help and make using DAO 3.6 a doddle.

Happying DAOing!

Louis Rose

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only two kinds of languages: the ones people complain about and the ones nobody uses” - Bjarne Stroustrup