René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

add_user_defined_property [Access macro]

option explicit

public sub add_user_defined_property ()

on error goto error_lbl

  dim ac  as access.application
  dim cnt as dao.container
  dim doc as dao.document
  dim prp as dao.property
  dim db  as dao.database

  dim mdb_name as string
      mdb_name = "c:\temp\cust_prop_test.mdb"

  set ac = new access.application
  set db = ac.dbEngine.workspaces(0).createDatabase(mdb_name, dbLangGeneral, 0)

  ac.openCurrentDatabase(mdb_name)
  
' set cnt = DBEngine(0)(0).Containers("Databases")
  set cnt = db.containers("Databases")

  ' following line throws "3265 Item not found in this collection"
  set doc = cnt.Documents!UserDefined
  
  set prp = doc.createProperty("MyNewProperty", dbText, "MyNewProperty")
  doc.properties.append prp
  
' for Each prp In doc.Properties
'     debug.print "Name = " & prp.Name & ", value = " & prp.Value
' next

error_lbl:
  
  select case err.number
         case 3265
              msgBox("Expected error occured")
         case else
              msgBox(err.number & vbCrLf & err.description)
  end select

end sub