1. CJ Lai
  2. PowerBuilder
  3. Friday, 8 November 2019 19:53 PM UTC

Hi PBers

I have searched on Google for a solution to this issue for a while now and I am turning to you for help.

I have a saved doc in Word with 'fields' (not 'bookmarks') in it. I did so by going to Insert>Quick Parts>Field...

I need to access said doc from PB to fill those fields.

 

I am able to:

- create an ole and connect it to word.application

- open the doc in the ole

However, I am not able to:

- 'goto' those fields (they all have a 'name' in the doc such as '«Firstname»')

- fill the fields with data/string...

(The reason why I don't use 'bokmarks' instead is because the original Word doc would get modified with the data/strings AND lose those bookmarks even after an SaveAS. So...)

 

 

Please advise.

Thank you

CJ

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 11 November 2019 16:53 PM UTC
  2. PowerBuilder
  3. # 1

Hi, 

I find it very strange that your document / template is automatically saved when you simply do a SaveAs.

Maybe it has to do with one of these settings of your Word? (this is office 2016)

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Saturday, 9 November 2019 08:16 AM UTC
  2. PowerBuilder
  3. # 2

Maybe this might be also a useful link:

https://community.appeon.com/index.php/qna/q-a/mail-merge-letters

 

Comment
  1. CJ Lai
  2. Tuesday, 12 November 2019 19:21 PM UTC
That's a helpful link but the info doesn't relate to what I need to achieve. I am not doing any mail merge per se. I need to populate a patient chart with demographic, vital, and other info.
  1. Helpful
  1. Miguel Leeuwe
  2. Tuesday, 12 November 2019 19:30 PM UTC
If you have a chart, that chart feeds itself from a table with data I suppose. As I suggested in a previous answer, do what you want to do from powerbuilder while recording a macro. Then edit the recorded macro, it should give you information of what you could do from powerbuilder with OLE.

regards and good luck.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Saturday, 9 November 2019 08:14 AM UTC
  2. PowerBuilder
  3. # 3

You say you don't use "bookmarks" because they would be replaced in the original document, even if you don't save the original document and doing a SaveAs()?

Try to use a "template" document as the original document (.dot or .dotx). See if the problem still exists.

Comment
  1. Miguel Leeuwe
  2. Tuesday, 12 November 2019 03:00 AM UTC
As a last solution. First make a copy (from code) of the document, work with the copy and when done, delete it.
  1. Helpful
  1. CJ Lai
  2. Tuesday, 12 November 2019 19:28 PM UTC
I think I found out what I needed to do to prevent that from happening.

Since I issue a Close() at the end of the operation to close the OLE, the command by itself includes a SAVE in it. That's why my original doc was saved with changed on it.

Thanks to Dennis Little's (https://bit.ly/2KgC75a) help in this post - https://bit.ly/2Kdj63O all I need to do is to do a Saved = True before Close() to trick PB. Now I have my original doc intact.
  1. Helpful
  1. Miguel Leeuwe
  2. Tuesday, 12 November 2019 19:31 PM UTC
That's great news!
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 8 November 2019 21:29 PM UTC
  2. PowerBuilder
  3. # 4

What it sounds like is that you are trying to do a mail merge. If you're on 2016, goto the menu "mailings", "mail merge" .

Once you've figured out how to do the mail merge in Word,

- start recording a macro (in the "view" menu)  and

- go through the whole process of doing the merge in word.

- When finished, stop recording your macro and edit it.

There you find find the VBA code which corresponds to the OLe commands that you can run in powerbuilder to do the same.

 

We've got this done somewhere in our old code, but it will cost me a bit to get a working example.

I've tried to google on this, but I couldn't find a clear simple working example. Maybe you are more lucky or someone might still have a working example, since this is 'old school'.

 

Let us / me know if you need any help.

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 8 November 2019 20:52 PM UTC
  2. PowerBuilder
  3. # 5

Hi, CJ - 

I have not done this, but here is where I go look to find out what I can or cannot do in Word via OLE:

https://docs.microsoft.com/en-us/office/vba/api/word.field

I suggest you examine the Methods and Properties of the Field object for clues. Perhaps the "Data" property?

Good luck!
John

Comment
  1. CJ Lai
  2. Tuesday, 12 November 2019 19:33 PM UTC
Hi John

That is a great link but not all applies to PB. For instance, in PB OLE, FormFields.Count is recognized and functional. However, anything else with "FormFields" is invalid in PB (it treats that as an invalid external function call) even though all I have in my doc are 'fields.'

BUT, if I replace FormFields with Bookmarks in those calls, it works ( I am still figuring out how to make my Checkbox 'field' checked)
  1. Helpful
  1. John Fauss
  2. Tuesday, 12 November 2019 19:46 PM UTC
I'm sorry the link I provided was not more help to you, CJ. Best wishes!
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.