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
Comments