BusinessObjects Board

Vba to list all objects used in conditions

Hi all,

I’ve used Dave’s code to identify the list of objects used in a report. Thanks !!! :lol:

I want to list in a csv file all the objects used in the conditions of each dataprovider of a set of document.

I have a problem with dataprovider with no conditions. :reallymad:
My code is not correct. I just want to go to the next dataprovider if there is no condition.

my code is :
If MyDocument.DataProviders.Queries.Item(j).Conditions.Count >= 1 Then Print MyDocument.DataProviders.Queries.Item(j).Conditions.Item(l).Object
End if

j is the number of dataprovider
l the number of conditions

Any help ?

Regards

Is that your actual code? Wouldn’t the Print need to followed by the file reference (Print #1, for example)? What is the error that you are seeing? Maybe you need to show us more of the code to put things in context … how you’re looping variables (i and j) are controlled, for example.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Hi Dwayne,

I try to modify Dave’s code :

Sub ConditionsPerDoc()
    Dim strCurrentFile As String
    Dim docMyDocument As Document
    Dim dpMyDataProvider As DataProvider
    Dim dpColumn As Column
    Dim strName As String
    
    Dim strNextItem As String   ' used to parse comma listed table names
    Dim strDocPath As String    ' Path to use to look for files
    Dim strObjList As String    ' Path for output file
    Dim strUniverseCondition As String
    Dim strErrorLog As String   ' Path for error log

    Dim i, j, k, l As Integer   ' loop counters
    Dim x As Integer            ' function result value
    
    ' Start directory list of .rep files in the standard file location. If you want to load files
    ' from a different directory, you would hard code the value below. Make sure that a hard-coded
    ' path includes the trailing back slash!
    
    strDocPath = Application.GetInstallDirectory(boDocumentDirectory) & "\"
    strObjList = strDocPath & "ConditionsPerDoc.csv"
    strErrorLog = strDocPath & "ConditionsPerDoc.log"
    
    If FileExist(strObjList) Then
        Kill (strObjList)
    End If
    If FileExist(strErrorLog) Then
        Kill (strErrorLog)
    End If
    
    strCurrentFile = Dir(strDocPath & "*.rep")
    
    ' Do while there are reports we have not looked at
    Do While strCurrentFile <> ""
      
      If strCurrentFile <> ThisDocument.Name &amp; ".rep" Then

        Set docMyDocument = Application.Documents.Open(strDocPath &amp; strCurrentFile)
        
        If docMyDocument.Name <> "" Then
        
            For j = 1 To docMyDocument.DataProviders.Count
            
                Set dpMyDataProvider = docMyDocument.DataProviders.Item(j)
                If dpMyDataProvider.GetType = "DPQTC" Then  ' This is a dataprovider from a universe
                    
                    ' Get the name associated with the data provider
                    strName = dpMyDataProvider.Name                    
                    
                    If dpMyDataProvider.Queries.Item(j).Conditions.Count >= 1 Then
                    ' For Each Cond In dpMyDataProvider.Queries.Item(j).Conditions
                    Open strObjList For Append As OutNum
                    For l = 1 To dpMyDataProvider.Queries.Item(j).Conditions.Count
                    ' Get the queries associated with the data provider
                    strUniverseCondition = dpMyDataProvider.Queries.Item(j).Conditions.Item(l).Object
                    
                    ' Next step will be to parse the data provideres and write out to
                    ' an output file the comma separated list of objects used
                    
                    Print #OutNum, strName; "; "; strUniverseCondition; ""
                    ' Next Cond
                    Next l
                    Close OutNum
                    End If
                    
                End If
            
            Next j  ' Next data provider, if any more
            
        End If
        
        docMyDocument.Close
        
      End If
        
      ' Get next document, if there is one.
      strCurrentFile = Dir
   Loop
    
End Sub

{moderator edit: BBCode formatting added to improve readability of code sample}

this code works when a dataprovider has one or more conditions but doesn’t when there is no conditions !

Thanks

A quick glance at the code doesn’t show any problems to me. Exactly what does “doesn’t work” mean? An error? Unexpected results?


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Error : Invalid index on the dataprovider with no condition.

on this more specially : dpMyDataProvider.Queries.Item(j).Conditions.Count =

Regards

Hmmm … that tells me the j value (the only index in that statement) is bad.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Ok thanks Dwayne

I’ll check and tell you

Regards

In the meantime, if you have a tech support ID, take a look at this article. It’s one of my SDK presentations from this past User Conference, and contains a utility that documents all the objects used in a series of report file. Maybe some code from that will give you some ideas.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Hi Dwayne,

Thanks very much !!! :blue:

Regards

You are quite welcome.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Hi Dwayne,

You seem to be an old user of BO !

Business is good in your area ?

Regards

I’ve only been using BusObj less than four years actually …

And business? Well, I’m not a consultant … my job is in-house. With the persistent downsizing at most corporations (including mine), my “business” is quite good … meaning I’m “swamped” … and I don’t mind at all :slight_smile: .


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

I succeed to solve my problem. I’ll send you.

In four years you seem to know a lot about the product. I work on it since 1998 since version 3 !!

Regards

Dwayne,

I just use this :

dpMyDataProvider.Load
                   ...
                    dpMyDataProvider.Unload

Now it works :roll_eyes: :wink:

Regards

Hi all,

Here is an other way (a better one) to list all objects and conditions used in a doc. Check this post.

Regards