2

I have the following block of code that iterates through the fields of each table and adds the fields of the current table respectively in order to create a number of tableboxes.

'iterate through every table
For i=1 To arrTCount
  'the arrFF array holds the names of the fields of each table
  arrFF = Split(arrFields(i), ", ")
  arrFFCount = UBound(arrFF)

  'create a tablebox
  Set TB = ActiveDocument.Sheets("Main").CreateTableBox

  'iterate through the fields of the array
  For j=0 to (arrFFCount - 1)
      'add the field to the tablebox
      TB.AddField arrFF(j)
      'Msgbox(arrFF(j))
  Next

  Set tboxprop = TB.GetProperties
  tboxprop.Layout.Frame.ObjectId = "TB" + CStr(i)
  TB.SetProperties tboxprop
Next

The above code creates the tableboxes, but with one field less every time (the last one is missing). If I change the For loop from For j=0 To (arrFFCount - 1) to For j=0 To (arrFFCount) it creates empty tableboxes and seems to execute forever. Regarding this change, I tested the field names with the Msgbox(arrFF(j)) command and it shows me the correct field names as I want them to be in the tableboxes in the UI of QlikView.

Does anybody have an idea of what seems to be the problem here? Can I do this in a different way?

To clarify the situation here and what I have tested so far, I have 11 tables to make tableboxes of and I have tried with just one of them or some of them. The result I am seeing with the code is on the left and what I am expecting to see is on the right of the following image. Please note that the number of fields vary for each table and the image has just one of them as an example.

enter image description here

Michail N
  • 3,647
  • 2
  • 32
  • 51
  • have you tried encapsulation the field names in square brackets? i.e [field] – EldadT May 09 '18 at 10:29
  • @EldadT if you mean this TB.AddField [arrFF(j)] then yes I tried it and the result is that it is "executing forever" – Madison Scodelario May 09 '18 at 10:53
  • how about var fld = "["+arrFF(j)+"]" and then TB.AddField fld – EldadT May 09 '18 at 11:02
  • @EldadT, thank you for the effort and the explanation, but again I face the same problem – Madison Scodelario May 09 '18 at 11:30
  • try to change the name of that last missing field. sounds like the name is the problem – EldadT May 09 '18 at 12:04
  • @EldadT I edited my question and I have tried with different field names. The problem here is that I am seeing results with one field less with the for loop I have in the code above, and blank tables except from the first table (whichever table does not matter) with its first field only along with the never ending execution if I change it to iterate all the fields as shown with the Msgbox command. – Madison Scodelario May 09 '18 at 12:55
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170691/discussion-between-madison-scodelario-and-eldadt). – Madison Scodelario May 09 '18 at 13:01

0 Answers0