Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3757394
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:59:56+00:00 2026-05-19T09:59:56+00:00

I am looking for a way to create a custom property in access with

  • 0

I am looking for a way to create a custom property in access with VBA.

Here’s how far I am and where I am stuck:

A custom property’s value (whose name is foo) can be read like so:

Dim cnt As Container
Dim doc As Document

Set cnt = DBEngine(0)(0).Containers!Databases
Set doc = cnt.Documents!userDefined

doc.Properties.Refresh
Debug.Print (doc.Properties!foo)

Similary, I can create a new property:

doc.Properties.Append doc.CreateProperty("vba created", dbText, "yes")

Now, the problem is:

Set doc = cnt.Documents!userDefined

does only work when I have already at least one custom property in the mdb. So, in order to create a custom property with VBA, I need to create a custom property.

I don’t want to create this custom property manually (which would work) because I need
to create a few MDBs with VBA and would like to do everything without manual intervention.

Thanks for any pointer to the right direction

Rene

EDIT for clarity

Here’s a (trimmed down) code that I hope can be used to demonstrate what I cannot accomplish:

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

This code throws the 3265 (Item not found in this collection) error at the line reading

  set doc = cnt.Documents!UserDefined

because (as I think) the mdb is newly created and does not yet contain the userDefined member in cnt.Documents. It would work, if I had already manually added such a property, that is, by opening the mdb file with access, then going to menu File->Database Properties then going to the custom tab.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:59:57+00:00Added an answer on May 19, 2026 at 9:59 am

    The problem is that you are using createdatabase to create the DB file. Creating the MDB file this way only creates the MSysDB document object.

    To create the database as you are trying to do and be able to set a property in the documents!userdefined object, you must create the database from the application.

    To do this, change these lines:

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

    to:

      set ac = new access.application
      ac.NewCurrentDatabase (mdb_name)
    
      Set db = ac.CurrentDb
    

    This will create a .mdb file and it will have 3 documents in it named MSysDb, SummaryInfo and UserDefined.

    Your code helped me solve the problem I was working on, hopefully this helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to create a data access layer that can either
I am looking for a way to create a ZIP file from a folder
I'm looking for a way to create an online form that will update an
I'm looking for a way to create an it will look cool effect for
I'm looking for any way that I can improve the selector performance of a
I'm looking for a way to set up my own default property values for
I am looking for a way to create dynamic preferences where I don't need
I'm looking for way to PHP to detect if a script was run from
I am using the jquery-ui-dialog plugin I am looking for way to refresh the
I looking for a way, specifically in PHP that I will be guaranteed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.