DI Management Home > Microsoft Access Classes > Editing and deleting objects

Editing and deleting objects


<< Back to Classes index page

Introduction

This example shows how to extend our clsOrder object with methods that allow you to Edit and Delete the database records.

Instructions

  1. Create a new class module clsOrder1 with this code (clsOrder1.txt).
  2. Experiment with this new object in the Debug Window as follows:
    ' Create an new instance of object in memory
    Set oOrd = New clsOrder1
    
    ' Add properties to "empty" object
    oOrd.CustomerID = 1
    oOrd.Item = "Widget"
    oOrd.Qty = 200
    oOrd.UnitPrice = 5
    
    ' Save to database
    ? oOrd.Create
    True
    
    ' Check new ID
    ? oOrd.OrderID
     3
    
    ' Confirm then change value of Qty in object
    ? oOrd.Qty
     200 
    oOrd.Qty = 1000
    ? oOrd.Update
    True
    
    ' Load data from database again and check change has been done
    ? oOrd.OrderID
     3 
    ? oOrd.Load(3)
    True
    ? oOrd.Qty
     1000 
    
    ' Now delete the object from database
    ? oOrd.Delete
    True
    
    ' And now try and load it again
    ? oOrd.Load(3)
    False
    

    If you want to do this in a test code snippet instead, don't forget to change the "?" to "Debug.Print" (but if you've got this far, you'll know that already).

Things to note about the code

In the next example, we'll see how to use Collections to manage an order that has more than one detail. [Sorry. That's all folks!]

<< Back  | 

Contact

Any comments, feedback, questions: please send us a message.

This page first published circa 2000. Last updated 11 June 2014