Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Properties

Status
Not open for further replies.

sdimov

Programmer
Jul 20, 2001
22
0
0
US
Part of what collection are the database properties that appear on the Summary tab on the dialog box Database Properties accessed through File>> Database Properties>>Summary Tab (Title, Subject, Author, Manager, etc...)
If I created those I can access them but aren't they already stored somewhere?

Thanks
 
Actually, I found what I was looking for...

Svet Dimov
 
For those that are curious, here is the answer to my question:

Option Compare Database
Option Explicit

Sub GetSummaryInfo()

On Error GoTo ERROR_PROC

Dim db As DAO.Database
Dim doc As DAO.Document
Dim cnt As DAO.Container
Dim prp As DAO.Property
Dim lngCounter As Long

Set db = CurrentDb
Set cnt = db.Containers("Databases")
Set doc = cnt.Documents("SummaryInfo")

For Each prp In doc.Properties
Debug.Print "Property name: " & prp.Name & _
vbNewLine & _
"Property value: " & prp.Value & _
vbNewLine & vbNewLine
Next prp
Set doc = Nothing
Set cnt = Nothing
db.Close
Set db = Nothing

Exit Sub
ERROR_PROC:
End Sub
 
Svet, you may be interested that Custom properties can be used to persist settings with the MDB. Here is some code I am using for this:
Code:
Public Function SetCustomProperty(strPropName As String, intPropType _
    As Integer, vntPropValue As Variant) As Boolean

    Dim dbs As Database, cnt As Container
    Dim doc As Document, prp As Property

    Const conPropertyNotFound = 3270    ' Property not found error.
    Set dbs = CurrentDb                 ' Define Database object.
    Set cnt = dbs.Containers!Databases  ' Define Container object.
    Set doc = cnt.Documents!UserDefined ' Define Document object.
    On Error GoTo SetCustom_Err
    doc.Properties.Refresh
    ' Set custom property name. If error occurs here it means
    ' property doesn't exist and needs to be created and appended
    ' to Properties collection of Document object.
    Set prp = doc.Properties(strPropName)
    prp = vntPropValue                  ' Set custom property value.
    SetCustomProperty = True

SetCustom_Bye:
    Exit Function

SetCustom_Err:
    If Err = conPropertyNotFound Then
        Set prp = doc.CreateProperty(strPropName, intPropType, vntPropValue)
        doc.Properties.Append prp       ' Append to collection.
        Resume Next
    Else                                ' Unknown error.
        SetCustomProperty = False
        Resume SetCustom_Bye
    End If
End Function

Public Function GetCustomProperty(strPropName As String) As Variant
    Dim dbs As Database, cnt As Container
    Dim doc As Document, prp As Property

    ' Property not found error.
    Const conPropertyNotFound = 3270
    On Error GoTo GetCustom_Err
    Set dbs = CurrentDb
    Set cnt = dbs.Containers!Databases
    Set doc = cnt.Documents!UserDefined
    doc.Properties.Refresh
    GetCustomProperty = doc.Properties(strPropName)

GetCustom_Bye:
    Exit Function

GetCustom_Err:
    Resume GetCustom_Bye
End Function

Public Sub DeleteCustomProperty(strPropName As String)
    Dim dbs As Database, cnt As Container
    Dim doc As Document, prp As Property

    ' Property not found error.
    Const conPropertyNotFound = 3270
    On Error GoTo DeleteCustom_Err
    Set dbs = CurrentDb
    Set cnt = dbs.Containers!Databases
    Set doc = cnt.Documents!UserDefined
    doc.Properties.Refresh
    doc.Properties.Delete strPropName

DeleteCustom_Bye:
    Exit Sub

DeleteCustom_Err:
End Sub

I found that it is best to use intPropType = dbText so that the values appear and are editable/deleteable in the "Custom" tab of Database Properties.

BTW, your suggestion to compact/repair the MDB to fix my compile button enabled problem in another thread did not work.

Kade Larsen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top