Problem with Merge to Word document with Fields

  • Thread starter Brett Kinross via AccessMonster.com
  • Start date
B

Brett Kinross via AccessMonster.com

Hello everyone

Using Word 2002 and Access 2002.

I have developed code to enable merging of data to different Word documents.
The problem lies in that when you merge to a new word document the Text Form
Fields Are Not Retained During Mail Merge.

This is a known problem which is detailed in the following document:
http://support.microsoft.com/default.aspx?scid=kb;en-us;286841

The above document also has a workaround macro in VBA from Word in which it
substitutes placeholders before the merge and then puts the text form Fields
back in after the merge.

I am having two problems with this code when automating from Access:
1) It has a variable called "aField" which isn't declared. This works fine
within Word but not Access. If you substitute "aField" for "fField" which is
a declared FormField variable it appears to work. Anyone know why the code
uses "aField" and why it works in Word but not Access?

2) The following line of code:
Selection.TypeText "<" & fFieldText(1, iCount) & "PlaceHolder>"
works fine within Word but can't get it to work in Access. In Access I have
tried it with:
WordDoc.Selection.TypeText "<" & fFieldText(1, iCount) & "PlaceHolder>"
where WordDoc is a declared object variable that is set to the Word Document.
I have also tried:
Wordapp.ActiveDocument.Selection.TypeText "<" & fFieldText(1, iCount) &
"PlaceHolder>"
where Wordapp is a declared object variable for Word.Application.

The error I always get is: "Object doesn't support this property or method."

Does anyone know how to typetext from Access to Word to the selected area?


Thanks for any assistance
Brett
 
A

Alex Dybenko

Hi,
I am having two problems with this code when automating from Access:
1) It has a variable called "aField" which isn't declared. This works fine
within Word but not Access. If you substitute "aField" for "fField" which
is
a declared FormField variable it appears to work. Anyone know why the code
uses "aField" and why it works in Word but not Access?

you can declare aField as Object
perhaps a module in word does not have option explicit - so declaration is
not required
2) The following line of code:
Selection.TypeText "<" & fFieldText(1, iCount) & "PlaceHolder>"
works fine within Word but can't get it to work in Access. In Access I
have
tried it with:
WordDoc.Selection.TypeText "<" & fFieldText(1, iCount) & "PlaceHolder>"
where WordDoc is a declared object variable that is set to the Word
Document.
I have also tried:
Wordapp.ActiveDocument.Selection.TypeText "<" & fFieldText(1, iCount) &
"PlaceHolder>"
where Wordapp is a declared object variable for Word.Application.

use:
Wordapp.Selection.TypeText "<" & fFieldText(1, iCount) & "PlaceHolder>"

also please note that you either need to set a reference to MS word to have
this code running, or use late bindings
 
B

Brett Kinross via AccessMonster.com

Thanks - worked well. My computer's hard drive crashed just after I
implemented the changes thus my delay in thanking you.

Once again thankyou for your time - much appreciated

Cheers
Brett

Alex said:
Hi,
I am having two problems with this code when automating from Access:
1) It has a variable called "aField" which isn't declared. This works fine
within Word but not Access. If you substitute "aField" for "fField" which
is
a declared FormField variable it appears to work. Anyone know why the code
uses "aField" and why it works in Word but not Access?

you can declare aField as Object
perhaps a module in word does not have option explicit - so declaration is
not required
2) The following line of code:
Selection.TypeText "<" & fFieldText(1, iCount) & "PlaceHolder>"
[quoted text clipped - 8 lines]
"PlaceHolder>"
where Wordapp is a declared object variable for Word.Application.

use:
Wordapp.Selection.TypeText "<" & fFieldText(1, iCount) & "PlaceHolder>"

also please note that you either need to set a reference to MS word to have
this code running, or use late bindings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top