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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get Database File Properties, title, subject

Status
Not open for further replies.

VelNPS

Programmer
Dec 5, 2003
8
US
Dear Tipmasters:

I would like to get at the "Database Properties" that you see when you select file>>Database>>Properties>>Summary menu items. I would like to use an ADO hierarchy but this may be above that in the "workspace" that I do not understand very vell. I have some code in DAO that works but can not convert it. Help is appreciated on the conversion.

Existing DAO Code:

Function GetSummaryInfo(strPropName As String, Optional varFileName As Variant) As String
' Comments: Get "Summary" properties of Database. Taken
' from Access97 help file.
' Parameters: strPropName = Name of property
' Return: "None" is returned if the property hasn't already been set.
' If an unknown error occurs, a zero-length string (" ") is returned.
' Dependencies: None
' Created: 9/15/00 MAW
' Modified:6/19/01 SDK to accept varFileName as additional arg. to work with external db's.
'
' --------------------------------------------------------
Dim dbs As Database, cnt As Container
Dim doc As Document, prp As Property

' Property not found error.
Const conPropertyNotFound = 3270
On Error GoTo GetSummary_Err

If IsMissing(varFileName) Then
Set dbs = CurrentDb
Else
On Error Resume Next
Set dbs = DBEngine.OpenDatabase(varFileName)
If Err <> 0 Then
GetSummaryInfo = ""
GoTo GetSummary_Bye
End If
End If

Set cnt = dbs.Containers!Databases
Set doc = cnt.Documents!SummaryInfo
doc.Properties.Refresh
GetSummaryInfo = doc.Properties(strPropName)

GetSummary_Bye:
Set dbs = Nothing
Set cnt = Nothing
Set doc = Nothing
Exit Function

GetSummary_Err:
If Err = conPropertyNotFound Then
Set prp = doc.CreateProperty(strPropName, dbText, "None")
' Append to collection.
doc.Properties.Append prp
Resume
Else

' Unknown error.
GetSummaryInfo = ""
Resume GetSummary_Bye
End If
End Function
 

If you're using VB6 you can convert this code by setting a project reference to Microsoft DAO 3.6 Object Library and dim your variables prefixed with "DAO."

Code:
Function GetSummaryInfo(strPropName As String, Optional varFileName As Variant) As String
  ' Comments: Get "Summary" properties of Database.  Taken
  '           from Access97 help file.
  ' Parameters: strPropName = Name of property
  ' Return: "None" is returned if the property hasn't already been set.
  '         If an unknown error occurs, a zero-length string (" ") is returned.
  ' Dependencies: None
  ' Created: 9/15/00 MAW
  ' Modified:6/19/01 SDK to accept varFileName as additional arg. to work with external db's.
  '
  ' -------------------------------------------------------
  Dim dbs As [red]DAO.[/red]Database, cnt As [red]DAO.[/red]Container
  Dim doc As [red]DAO.[/red]Document, prp As [red]DAO.[/red]Property

  ' Property not found error.
  Const conPropertyNotFound = 3270
  On Error GoTo GetSummary_Err
  
  If IsMissing(varFileName) Then
    Set dbs = CurrentDb
  Else
    On Error Resume Next
    Set dbs = DBEngine.OpenDatabase(varFileName)
    If Err <> 0 Then
        GetSummaryInfo = ""
        GoTo GetSummary_Bye
    End If
  End If
  
  Set cnt = dbs.Containers!Databases
  Set doc = cnt.Documents!SummaryInfo
  doc.Properties.Refresh
  
  [red]For Each prop In doc.Properties
    Debug.Print prop.Name & ": " & prop.Value
  Next[/red]
  
  GetSummaryInfo = doc.Properties(strPropName)

GetSummary_Bye:
  Set dbs = Nothing
  Set cnt = Nothing
  Set doc = Nothing
  Exit Function

GetSummary_Err:
  If Err = conPropertyNotFound Then
    Set prp = doc.CreateProperty(strPropName, dbText, "None")
    ' Append to collection.
    doc.Properties.Append prp
    Resume
  Else

' Unknown error.
    GetSummaryInfo = ""
    Resume GetSummary_Bye
  End If
End Function


Mark

&quot;You guys pair up in groups of three, then line up in a circle.&quot;
- Bill Peterson, a Florida State football coach
 
Thank you very much for the reply, However, I am trying to remove the reference to DAO and use exclusively ADO within MS Access.

Any other ideas?
 
hi VelNPS,

Did you solve this problem? I´m looking for the same solution and could use some help.

 
You might want to try looking into ADOX (Microsoft ADO Ext. 2.x for DDL and Security). This is an ADO library that allows querying of database/table/column(field) properties. I'm not sure if it covers the same properties as the DAO model, but it does cover quite a bit. Search in the VB 5&6 forum or in Google and you should get a good deal of info.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top