iterating database properties? 
Author Message
 iterating database properties?

I'm trying to do something like the following, which doesn't work:

    For Each prp in CurrentDb.Properties: ? prp.Name & "=" &  prp.value:
next prp

I'm writing generic code to document databases and was hoping to dump the
list of properties and their values to a file.

When the above code is run, it always generates error 3251:  "Operation is
not supported for this type of Object." for certain properties (e.g.
currentdb.Connection), i.e. their .value cannot be refered to.  I am
guessing this behaviour will vary from one context to the next.

I suppose I could trap that error and Resume Next to get all the valid ones.

Sorting the entries alphabetically would be nice too.  I can immediately can
think of 3 ways of doing that:  load the property strings into an array and
sort it (with an algorithm like quickSort), load them into a table and sort
it, then retrieve them, write them to the file, delete the table, and, the
simplest: write them to a file, one entry per line, and sort the file by
shelling the command-line Sort utility.  The shell("Sort ...") idea sounds
like a winner, but introduces the possible problem with asynchronous
execution, which is pretty easy to overcome and probably isn't an issue at
all here anyway.



Quote:
> For Each prp in CurrentDb.Properties: ? prp.Name: next prp

> right in the debug window will iterate props. You cannot
> handle the values this way always since some props are
> unavailable and others can be objects. What exactly are you
> looking for, here?

> --
> MichKa

> -------------------------------------
> don't send questions by e-mail unless
> you're paying for it. (TANSTAAFL!) :-)

> random junk of dubious value and
> replica error and problem fixing at:
> http://www.*-*-*.com/



> irnews.net...
> > How does on loop through the names and settings of all
> properties in a
> > database?
> > I've hand no success with the properties collection - it
> always generates
> > errors.
> > Should one use containers?  I've had similar problems
> there.  Sample code
> > I've seen never works.

> > Also, how does one get the comments for objects such as
> queries and forms
> > (the comments that show up in detail view, set in the
> property tab for the
> > object)?

> > Thanks very much.



Thu, 04 Apr 2002 03:00:00 GMT  
 iterating database properties?

Well, here's an example that works.  It seems to only fail on the Connection
property, which must be some non-printable type, perhaps an object of some
kind.

What it doesn't do is return the really informative stuff, like the
comments, creator, the things one can enter in the "General", "Summary",
"Statistics", "Contents", "Custom" tabs - especially Custom and Summary -
when one looks at the database properties dialog.  Can one retrieve any of
things?  Are they available in a container?

Thanks again.

'code begins:
'------------------

Public Function listDBproperties(Optional DBName As Variant = "*", Optional
log As Boolean = False, Optional logFile As Variant = "*")

    'what one might want to do:
    'load it into an array or collection
    'write it to the debug window
    'write it to a file

    On Error GoTo Error

    logFile = trim(logFile)

    DBName = trim(DBName)

    Dim DB As Database

    If DBName = "*" Then
        Set DB = CurrentDb
    Else
        'set the database to the specified file; one might want
error-handling here:
        Set DB = Workspaces(0).OpenDatabase(DBName, , True)
    End If

    Dim prop As Property
    Dim propString As String

    Debug.Print: Debug.Print
    Debug.Print "Properties in " & CurrentDb.Name & ":"
    Debug.Print

    If logFile <> "*" And log Then

        Dim fn As Long
        fn = FreeFile

        Open logFile For Output As #fn

        For Each prop In DB.Properties
            propString = prop.Name & "="
            '*MUST* be split into 2 lines for RESUME NEXT to catch the name
but disregard the value
            propString = propString & prop.Value

            Debug.Print propString
            Print #fn, propString
        Next prop

        Close #fn

    Else

        For Each prop In DB.Properties
            propString = prop.Name & "="
            '*MUST* be split into 2 lines for RESUME NEXT to catch the name
but disregard the value
            propString = propString & prop.Value

            Debug.Print propString

        Next prop

    End If

    Debug.Print: Debug.Print

    Exit Function
Error:
    Select Case err.number
        Case 3251
            '"Operation is not supported for this type of Object."
            propString = propString & "NOT AVAILABLE"
            Resume Next
        Case Else
            err.Raise err.number
    End Select

End Function



Thu, 04 Apr 2002 03:00:00 GMT  
 iterating database properties?
Quote:

> Well, here's an example that works.  It seems to only fail on the Connection
> property, which must be some non-printable type, perhaps an object of some
> kind.

> What it doesn't do is return the really informative stuff, like the
> comments, creator, the things one can enter in the "General", "Summary",
> "Statistics", "Contents", "Custom" tabs - especially Custom and Summary -
> when one looks at the database properties dialog.  Can one retrieve any of
> things?  Are they available in a container?

<snip>

Yes, look for them in
CurrentDb.Containers("Databases").Documents("UserDefined").Properties,
but only for databases created via Access UI.



Thu, 04 Apr 2002 03:00:00 GMT  
 iterating database properties?
I think this is exactly what I said earlier. You can always
get the name, but you cannot always get the value. In
particular, the connection prop is only valid for ODBCDirect
workspaces.

The props you are looking for are NOT off the database, they
are off the SummaryInfo doc in the Databases container. See
the help topic on the "ReplicationConflictFunction" for an
example of scrolling down into this neck of the woods.

--
MichKa

-------------------------------------
don't send questions by e-mail unless
you're paying for it. (TANSTAAFL!) :-)

random junk of dubious value and
replica error and problem fixing at:
http://www.trigeminal.com



irnews.net...

Quote:

> Well, here's an example that works.  It seems to only fail
on the Connection
> property, which must be some non-printable type, perhaps
an object of some
> kind.

> What it doesn't do is return the really informative stuff,
like the
> comments, creator, the things one can enter in the

"General", "Summary",
Quote:
> "Statistics", "Contents", "Custom" tabs - especially

Custom and Summary -
Quote:
> when one looks at the database properties dialog.  Can one
retrieve any of
> things?  Are they available in a container?

> Thanks again.

> 'code begins:
> '------------------

> Public Function listDBproperties(Optional DBName As

Variant = "*", Optional

- Show quoted text -

Quote:
> log As Boolean = False, Optional logFile As Variant = "*")

>     'what one might want to do:
>     'load it into an array or collection
>     'write it to the debug window
>     'write it to a file

>     On Error GoTo Error

>     logFile = trim(logFile)

>     DBName = trim(DBName)

>     Dim DB As Database

>     If DBName = "*" Then
>         Set DB = CurrentDb
>     Else
>         'set the database to the specified file; one might
want
> error-handling here:
>         Set DB = Workspaces(0).OpenDatabase(DBName, ,
True)
>     End If

>     Dim prop As Property
>     Dim propString As String

>     Debug.Print: Debug.Print
>     Debug.Print "Properties in " & CurrentDb.Name & ":"
>     Debug.Print

>     If logFile <> "*" And log Then

>         Dim fn As Long
>         fn = FreeFile

>         Open logFile For Output As #fn

>         For Each prop In DB.Properties
>             propString = prop.Name & "="
>             '*MUST* be split into 2 lines for RESUME NEXT
to catch the name
> but disregard the value
>             propString = propString & prop.Value

>             Debug.Print propString
>             Print #fn, propString
>         Next prop

>         Close #fn

>     Else

>         For Each prop In DB.Properties
>             propString = prop.Name & "="
>             '*MUST* be split into 2 lines for RESUME NEXT
to catch the name
> but disregard the value
>             propString = propString & prop.Value

>             Debug.Print propString

>         Next prop

>     End If

>     Debug.Print: Debug.Print

>     Exit Function
> Error:
>     Select Case err.number
>         Case 3251
>             '"Operation is not supported for this type of
Object."
>             propString = propString & "NOT AVAILABLE"
>             Resume Next
>         Case Else
>             err.Raise err.number
>     End Select

> End Function



Thu, 04 Apr 2002 03:00:00 GMT  
 iterating database properties?
I believe the props he wants are in SummaryInfo?

--
MichKa

-------------------------------------
don't send questions by e-mail unless
you're paying for it. (TANSTAAFL!) :-)

random junk of dubious value and
replica error and problem fixing at:
http://www.trigeminal.com


Quote:

> > Well, here's an example that works.  It seems to only

fail on the Connection
Quote:
> > property, which must be some non-printable type, perhaps
an object of some
> > kind.

> > What it doesn't do is return the really informative
stuff, like the
> > comments, creator, the things one can enter in the

"General", "Summary",
Quote:
> > "Statistics", "Contents", "Custom" tabs - especially

Custom and Summary -
Quote:
> > when one looks at the database properties dialog.  Can
one retrieve any of
> > things?  Are they available in a container?

> <snip>

> Yes, look for them in

CurrentDb.Containers("Databases").Documents("UserDefined").P
roperties,
Quote:
> but only for databases created via Access UI.



Thu, 04 Apr 2002 03:00:00 GMT  
 iterating database properties?
Thanks for correction Michael. I guess I got too involved with the
UserDefined lately <g>
Quote:

> I believe the props he wants are in SummaryInfo?

> --
> MichKa

> -------------------------------------
> don't send questions by e-mail unless
> you're paying for it. (TANSTAAFL!) :-)

> random junk of dubious value and
> replica error and problem fixing at:
> http://www.trigeminal.com




> > > Well, here's an example that works.  It seems to only
> fail on the Connection
> > > property, which must be some non-printable type, perhaps
> an object of some
> > > kind.

> > > What it doesn't do is return the really informative
> stuff, like the
> > > comments, creator, the things one can enter in the
> "General", "Summary",
> > > "Statistics", "Contents", "Custom" tabs - especially
> Custom and Summary -
> > > when one looks at the database properties dialog.  Can
> one retrieve any of
> > > things?  Are they available in a container?

> > <snip>

> > Yes, look for them in

> CurrentDb.Containers("Databases").Documents("UserDefined").P
> roperties,
> > but only for databases created via Access UI.



Fri, 05 Apr 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Iterating a form's property values

2. Iterate Properties on ContactItem

3. How to iterate through ContactItem properties?

4. Iterate through custom properties from VBA?

5. Q: Iterate a controls properties at runtime?

6. Iterating through the properties of an object?

7. Iterate through an object's properties (any object)

8. Iterating through properties of a VB com object at runtime

9. Iterating through class properties?

10. Iterating through the properties of an object

11. Iterate thru Groups in database window?

12. Iterating through list of available databases using SQLDMO

 

 
Powered by phpBB® Forum Software