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

Editing and deleting objects

<< Back to Classes index page


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


  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
    ' Check new ID
    ? oOrd.OrderID
    ' Confirm then change value of Qty in object
    ? oOrd.Qty
    oOrd.Qty = 1000
    ? oOrd.Update
    ' Load data from database again and check change has been done
    ? oOrd.OrderID
    ? oOrd.Load(3)
    ? oOrd.Qty
    ' Now delete the object from database
    ? oOrd.Delete
    ' And now try and load it again
    ? oOrd.Load(3)

    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 us

To contact us or comment on this page, please send us a message.

This page first published circa 2000. Last updated 11 June 2014. Reformatted for HTML5 on 22 June 2020.