Share via

Problem Creating Property With VBA

Anonymous
2023-03-29T18:20:34+00:00

I am trying to work with Access Database in VBA. I ran into some problems so I tried to debug in the immediate section.

In the Immediate section I tried:

Currentdb.CreateProperty "TMPProperty", 10, "Temp Property"

It did not throw an error.

I then tried:

?currentdb.Properties("TMPProperty").Value

The system said:

I tried using the built-in form for to add the property:

But:

?currentdb.Properties("TMPProperty").Value

Threw the same property not found.

I used:

For I = 0 to 55 : ? i & " : " & currentdb.Properties(i).Name : Next i

But TMPProperty was not in the set.

What am I doing wrong?

What am I doing wrong?

Microsoft 365 and Office | Access | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2023-03-29T23:05:25+00:00

You need to append the property to the database's Properties collection, e.g. With a function like this:

Public Sub AddProp(strPropName As String, varPropType As Variant, varPropValue As Variant)

    Dim dbs As DAO.Database

    Dim prp As DAO.Property

    Set dbs = CurrentDb

    Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)

    dbs.Properties.Append prp

End Sub

You can then call the function like this to create the property and assign it a value:

AddProp "MyProp",dbText,"My value"

And return its current value like this:

? CurrentDb.Properties("MyProp")

My value

And assign a new value to it like this:

CurrentDb.Properties("MyProp") = "My new value"

? CurrentDb.Properties("MyProp")

My new value

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2023-03-30T01:19:36+00:00

    What are you wanting to use this property for?

    Was this answer helpful?

    0 comments No comments