Create (by default) userdefined documents collection from VBA


I cannot figure out how could I created by default UserDefined document of databases container from VBA code, i.e.

set dbs = ...CreateDatabase(....)
set doc = dbs.containers![Databases].documents!UserDefined ' <----
this fails - item not found in this collection

I know I can create an empty template mdb from MS Access 97 IDE which have UserDefined document but the problem is that in this case it is a little bit hard to change ProjectName of such template mdb - you need to start another instance of MS Access 97 I guess...


This seems to be the only code template which can be used to create new mdb with UserDefined doc from VBA - I don't like it but do you know better, probably, indirect way but without Automation?

Public Sub NewMdbWithUserDefinedDocCreate()
    Dim dbs As Database
    Dim doc As Document
    Dim prp As Property
    Dim objAcc As New Access.Application
    Dim strMDBPath As String
    strMDBPath = "c:\das_tsts\!udefprp\ddd12.mdb"
    On Error Resume Next
    Kill strMDBPath
    On Error GoTo 0
    objAcc.Visible = False
    objAcc.NewCurrentDatabase strMDBPath
    Set objAcc = Nothing
    Set dbs = DBEngine(0).OpenDatabase(strMDBPath)
    Set doc = dbs.Containers![Databases].Documents!UserDefined
    For Each prp In doc.Properties
        Debug.Print "Name = " & prp.Name & ", value = " & prp.Value
    Set prp = doc.CreateProperty("MyNewProperty", dbText, "MyNewProperty")
    doc.Properties.Append prp
    Set prp = Nothing
    Set doc = Nothing
    Set dbs = Nothing
End Sub

Copyright 1999-2008 by Shamil Salakhetdinov. All rights reserved.