469,270 Members | 1,117 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Word Form Fields from Form with sub-form

Hello everyone,

I'm trying add a print button that opens a Word document and fills in form fields in the document based on the currently displayed record. The code works in a sample that I ran but I've run into a problem. The form I'm using contains both fields I need in the document and a sub-form with fields I need to populate the document. I get an error message 'MS Office Access can not find the field 'txtPOSIT2' referred to in your expression'. If I move the button (and code) to the sub-form, I get the same error message but the field name changes to 'txtLNAME'. My question is: Is there a way to use information from both the form and sub-form to populate the form fields in the Word document?

I'm using Access 2003 and Word 2003. I'll be happy to provide additional information.

Many thanks in advance,

Apr 5 '07 #1
3 3205
Ok, been thinking about a workaround. What about using a make-table query that creates a 'temporary' table to hold the fields needed to pass to the Word document? Question now is how do I programatically pass the values from the table to Word's form fields to print the contract? Also, what do I do with the table once the contract is printed? If I print one contract for Employee A, then move to Employee B to print a contract would I need to delete the 'temporary' table first? I'm thinking a macro will be needed to do all of this.

Any advice would be greatly appreciated.
Apr 5 '07 #2
I discovered where I was going wrong. When collecting the values of the form fields I was using the following code:

Expand|Select|Wrap|Line Numbers
  1. With doc
  2.         .FormFields("fldFNAME").Result = Nz(Me!txtFNAME)
  3.         .FormFields("fldLNAME").Result = Nz(Me!txtLNAME)
  4.         .FormFields("fldPOSIT2").Result = Nz(subContractData!txtPOSIT2)
  5.         .FormFields("fldSCHNAME1").Result = Nz(subContractData!txtSCHNAME1)
  6.         .FormFields("fldCONTRACTPAY").Result = Nz(subContractData!numCONTRACTPAY)
  7.         .FormFields("fldCONTRACTLENGTH").Result = Nz(subContractData!numCONTRACTLENGTH)
I was using the correct syntax for the first 2 fields but I was using 'Me' in the last 4 fields. Those 4 fields are part of the sub-form. After doing some reading and a lot of head-scratching I realized my mistake.

Just wanted to post the answer in case someone else searches for a similar problem.

Apr 6 '07 #3
14,534 Expert Mod 8TB
Thanks for posting the solution William. Glad you got the answer worked out.

Mary :)
Apr 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by MouseHart | last post: by
41 posts views Thread by Ruby Tuesday | last post: by
reply views Thread by beerman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.