Adding Multiple Condtions through VBA with same class,object

Hi All,

I am trying to add conditions from VBA taking the input values in the in list from a text file. I am successfully able to add the condtion but it accepts only 255 objects in the ‘In List’ ’ condition. I have more than 255 objects in the 'In list condition. So what I had done is spilt the objects in the flat file into strings of 255 and replace the string in the CONDTITION.ADD command.

I have put aloop and it will replace each string. Now what it should do is add as many conditions as the number of strings generated. But I am facing a problem here. When I am putting the CONDITIONS.ADD in a loop it is not adding as many conditions as the number of strings but it is overwriting the conditions and the last condtion added remains there. I am pasting my code below:

Sub temp() 'Reading the text file
Dim a As Integer
Dim sequence As Integer
Set fs = CreateObject("Scripting.FileSystemobject")
Set wfile = fs.openTextfile(Trim(UserForm1.TextBox1))

'Counting no of input values
inti = count_no_of_lines()
MsgBox (inti)
inti = (inti / 255) + 1
MsgBox (inti)
ReDim strData(inti)

inti = 0
blank = 0

'Converting input values into strings
Do While Not wfile.atendofstream
    counter = counter + 1
    If counter > 255 Then
        strData(inti) = strtext
        inti = inti + 1
        strtext = ""
        counter = 0
    End If
    singleline = wfile.readline
    If singleline = "" Then
        blank = blank + 1
    Else
        If strtext = "" Then
            strtext = singleline
        Else
            strtext = strtext + "," + Trim(singleline)
        End If
    End If
Loop
MsgBox (blank)
strData(inti) = strtext
 
For a = 0 To UBound(strData) - 1
    MsgBox strData(a)
Next
wfile.Close
Set wfile = Nothing
Set fs = Nothing
End Sub
Function count_no_of_lines()
    Dim inti
    Set fs1 = CreateObject("Scripting.FileSystemobject")
    Set wfile1 = fs1.openTextfile(Trim(UserForm1.TextBox1))
    inti = 1
    Do While Not wfile1.atendofstream
        wfile1.readline
        inti = inti + 1
    Loop
    Set wfile1 = Nothing
    Set fs1 = Nothing
    count_no_of_lines = inti
End Function


Function Read_text_Add() 'Creatint BO query
    Dim i, con_count, con_count1 As Integer
    strReportName = Application.ActiveDocument.Name
    Set doc = Application.Documents(strReportName)
    Set dp = doc.DataProviders(1)
    Set qy = dp.Queries.Item(1)
    Set cons = qy.Conditions
    
        
    con_count = cons.Count
        
    'Calling function temp for converting the given input file in string
    temp
    
    'storing values input from the form into variables
    classname = Trim(UserForm1.txtClassName)
    objectname = Trim(UserForm1.txtObjectName)
    conditionname = Trim(UserForm1.ComboBox1.Value) 'UserForm1.txtCondition
    
    If classname = "" And objectname = "" And conditionname = "" Then
          MsgBox "Report not refreshed successfully"
        End
    End If
    
    'Adding the conditions
     For i = 0 To UBound(strData) - 1
        'Dim str_text As String
        str_text = ""
        str_text = strData(i)
        strnull = Add_Condition(classname, objectname, conditionname, str_text)
    Next i
    
End Function
Function Add_Condition(ByVal classname As String, ByVal objectname As String, ByVal conditionname As String, ByVal strtext2 As String) 'Creatint BO query
    Dim doc As busobj.Document
    Dim con As Condition
    Dim cons As Conditions
    strReportName = Application.ActiveDocument.Name
    Dim string1 As String
    
    string1 = strtext2
    
    Set doc = Application.Documents(strReportName)
    Set dp = doc.DataProviders(1)
    Set qy = dp.Queries.Item(1)
    Set cons = qy.Conditions
        
    Application.Interactive = False
           Set con = cons.Add(classname, objectname, conditionname, string1)
     Application.Interactive = True

End Function

I am unable to find a solution. Can anybody please help?

Thanks in Anticipation,

Vikram Jain.


vikram_kumar (BOB member since 2004-02-10)