1. David Vasconcelos
  2. PowerBuilder
  3. Thursday, 6 May 2021 12:41 PM UTC

Trying to access a table, the following gives me an error

lole_temp = iole_word.ActiveDocument.Tables(1).Select

Error: Error calling external object function tables

All I am trying to do is get a tables content.  The table is created next to a bookmark so I need a way to use the bookmark as a reference (starting) point to then get access to the table so I can validate some info in its cells.

Above code was just a way to test if I can at least connect to a table., using table count I do get count of 4 so I know there are tables there.

PB17 R3, Office Pro..

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 6 May 2021 12:47 PM UTC
  2. PowerBuilder
  3. # Permalink

You can't use the short access of the Tables (or any other collection) using Tables(1).

Use the Item method instead:

lole_temp = iole_word.ActiveDocument.Tables.Item(1).Select

 

 

Comment
  1. David Vasconcelos
  2. Thursday, 6 May 2021 14:27 PM UTC
I can user tables.Count to see if it exists. Thanks for your help

  1. Helpful
  1. Mark Goldsmith
  2. Thursday, 6 May 2021 15:21 PM UTC
Hi David,



Glad you got it to work with René's approach and he is correct about not being able to use the Tables(1) format but I just wanted to point out the issue is more about the type of brackets being used rather than the short access approach.

For any collections square [] brackets must be used (from within PB) and if you had used these in your initial code it would select the table without an error.

When using the Item method, which is not referring to a collection but rather a single table, it doesn't matter that you use round brackets (). Actually, in this case when using the Item method you can use either round or square brackets and it will work but I tend to leave square brackets for collections for readability.



Regards...Mark
  1. Helpful
  1. René Ullrich
  2. Friday, 7 May 2021 04:20 AM UTC
Hi Mark,

good to know.

Thanks.
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.