1. CJ Lai
  2. PowerBuilder
  3. Friday, 08 November 2019

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
0
Votes
Undo

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.
  1. Monday, 11 November 2019
  2. PowerBuilder
  3. # 1
Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

Maybe this might be also a useful link:

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

 

Comment
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. CJ Lai
  2. Tuesday, 12 November 2019
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. Miguel Leeuwe
  2. Tuesday, 12 November 2019
There are no comments made yet.
  1. Saturday, 9 November 2019
  2. PowerBuilder
  3. # 2
Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

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
As a last solution. First make a copy (from code) of the document, work with the copy and when done, delete it.
  1. Miguel Leeuwe
  2. Tuesday, 12 November 2019
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. CJ Lai
  2. Tuesday, 12 November 2019
That's great news!
  1. Miguel Leeuwe
  2. Tuesday, 12 November 2019
There are no comments made yet.
  1. Saturday, 9 November 2019
  2. PowerBuilder
  3. # 3
Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

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.
  1. Friday, 8 November 2019
  2. PowerBuilder
  3. # 4
John Fauss Accepted Answer Pending Moderation
0
Votes
Undo

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
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. CJ Lai
  2. Tuesday, 12 November 2019
I'm sorry the link I provided was not more help to you, CJ. Best wishes!
  1. John Fauss
  2. Tuesday, 12 November 2019
There are no comments made yet.
  1. Friday, 8 November 2019
  2. PowerBuilder
  3. # 5
  • Page :
  • 1


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