0

Haven't found any info on this anywhere on the net (at least any that works--more on that in a moment).

What I am trying to do is have, at the push of a button that I have created in an Access Form, Word open a docx and populate it with certain rtf paragraphs (at certain points) on the basis of several TRUE/FALSE checkboxes in the record presently open in the Access Form.

Access code that works for passing values into the Word docx:

Function OpenWord(conPath As String)

Dim appword As Word.Application

Dim doc As Word.Document

On Error Resume Next

Error.Clear

Set appword = GetObject(, "word.application")

If Err.Number <> 0 Then

Set appword = New Word.Application

appword.Visible = True

End If

Set doc = appword.Documents.Open(conPath, , True)

With doc

.FormFields("TextName").Result = Me.Name

.FormFields("TextAnotherName").Result = Me.AnotherName

.FormFields("TextBoolean1").Result = Me.Boolean1

.FormFields("TextBoolean2").Result = Me.Boolean2

.FormFields("TextBoolean3").Result = Me.Boolean3

End With

appword.ActiveWindow.View.Type = wdPrintView

appword.Visible = True

appword.Activate

Set doc = Nothing

Set appword = Nothing

The above works great for passing names into the Word docx via Developer > Legacy > Text Form Field. The Boolean values also show up (i.e.: -1 for TRUE and 0 for FALSE). What I am trying to do is something along the lines of:

IF {TextBoolean1} = "0" "{ AUTOTEXT someparagraph}" ""

This internet suggestion does not work.

To summarize: What is needed to have Word 2013 insert a predefined paragraph (an autotext or quick part buliding block) in a predefined spot in a document on the basis of a boolean passed in from Access? (What is the way to do this?)

Thank you for all your kind help--this has had me stumped for a week trying various unfruitful avenues,

Stumped

1

Firstly I think you could simplify a lot of the code in your macro by using Mail merge from the Access database instead and just instigating that via macro.

The field code for your IF field as it appears here should work. Make sure that you have surrounded the code with special field brackets by clicking CTRL + F9 and not just regular brackets.

|improve this answer|||||
  • Thanks Adam. I actually had done as you had suggested. The problem actually was that while Word 'updated' the name fields upon opening the docx, the: IF {TextBoolean1} = "0" "{ AUTOTEXT someparagraph}" "" Field is not automatically updated (though it does the right thing on manual update). – Stumped Oct 29 '14 at 22:59
  • Fuller answer: Thanks Adam. I actually had done as you had suggested. The problem actually was that while Word 'updated' the name fields upon opening the docx, the: IF {TextBoolean1} = "0" "{ AUTOTEXT someparagraph}" "" Field is not automatically updated (though it does the right thing on manual update). Now I just need to figure out how to automate this field to update itself upon the opening of the docx. Thank you for your help--your conviction got me to poke around some more. – Stumped Oct 29 '14 at 23:07
  • @Stumped, glad to hear it's working. On the topic of automatically updating fields, I'm afraid Word doesn't offer this functionality, instead to achieve this you will once again need to use... a macro.. – Adam Oct 30 '14 at 0:08
  • In the case of an AUTOTEXT field nested inside an IF, the value will not update during merge and no field code will be left to update if you are merging to a new document. So you have to invert the IF, and use, e.g. { AUTOTEXT { IF { TextBoolean } = "0" "someparagraph" "blankautotext" } }, and create an autotext that is as blank as possible (manually, there has to be e.g. a space or perhaps a thin space) – user181946 Oct 31 '14 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.