[VBA] How to modify a dataprovider from VBA

Hi Guys,

Upon clicking on refresh, the users need to select to run the report on criteria A, B or C. We need to alter a dataprovider’s filters (where clause) according to the user’s selection.

We need to add two or three conditions seperated by OR.

We looked into the code ActiveDocument.DataProviders.item(1).Queries.item(1).Conditions.Add “Test Class”, “TestObject”, “Matches Pattern”, “QO%”, “Constant” but idd not manage to get it to work.

Anyone can help on this please? It really is important…

Thanks a lot!

Jonimatix


jonimatix :malta: (BOB member since 2007-12-03)

Nobody is ready to help regarding this issue? :shock:


jonimatix :malta: (BOB member since 2007-12-03)

Not sure if this would help, but we used the following to add ‘predefined’ conditions to a given dataprovider.


Sub AddCondition()
Dim oDoc As Document
Dim DPConditions As Conditions
Dim AllDPs As DataProviders
Dim CurrentDP As DataProvider
Dim strUniverseName As String
Dim DpCount As Integer
Dim x As Integer
Dim strPredefinedCond As String
Dim strClass As String

strUniverseName = "MyUniverse"
strPredefinedCond = "MyConditionName"
strClass = "MyClass"

Set oDoc = ThisDocument
Set AllDPs = ThisDocument.DataProviders

DpCount = oDoc.DataProviders.Count

For x = 1 To DpCount
    Set CurrentDP = AllDPs.Item(x)
    
    If CurrentDP.GetType = UCase(Trim("DPQTC")) Then
    CurrentDP.Load
       Set DPConditions = CurrentDP.Queries.Item(1).Conditions
        strUniverseName = CurrentDP.Universe
            If UCase(Trim(strUniverseName)) = "MyUniverse" Then
                    Call DPConditions.Add(strClass, strPredefinedCond)
            End If
               CurrentDP.Unload
    End If

Next x
End Sub

jresendez :mexico: (BOB member since 2004-05-03)