Formatting DocVariable fields in a Word Doc when printing from Acc

O

OssieMac

Not sure if I should be posting this in Access or Word forum but since I am
trying to do what I want from Access I thought I would try here first.

I have an Access procedure to copy some data from a form in Access to
DocVariable fields in a word document and print the document. All works fine
except for some unknown reason, I keep getting a mixture of bold and normal
font in the DocVariable fields of the word document.

I thought that it would be easy to simply format these DocVariable fields
after copying the data to them but I cannot find the right code to do so.

Any help will be greatly appreciated including any alternative ways of
achieving the desired result because I am quite new to Access and know even
less about Word so perhaps I am not going about this the correct way. The
following is a cut down sample of the code. I have included a line that I
thought should format the DocVariable but it does not work.

Private Sub PrintWordDoc_Click()

Dim strRecipName As String
Dim objWord As Object
Dim strPathFileName As String
'Following line required or "Variable not defined error" when
'compiling with option explicit even though it is a Word VB constant.
Dim wdDoNotSaveChanges 'Used to close document without saving

'Save the forms values to variables
'Space used in lieu of null values in the Nz function because if zero length
'string used for any field then the following gets printed on the Word doc:-
'Error! No document variable supplied.
strRecipName = Nz(Forms![Recipient Delivery List]. _
[SelectedRecipient], " ")

Set objWord = CreateObject("Word.Application")

'Save required path and filename of template file
strPathFileName = CurDir & "\" & "TextMerg.dot"

With objWord
'Create a new Word document based on the template
.documents.Add template:=strPathFileName
.Visible = True

'Copy data to the DocVariables on the Word Document
.ActiveDocument.variables("Recipient").Value = strRecipName
.ActiveDocument.Fields.Update

'The following line is the one with which I need the help
'.ActiveDocument.variables("Recipient").Font.Bold = True

'Following lines work but commented out during testing
'.ActiveDocument.PrintOut
'.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'.Quit
End With

End Sub

Thanks in advance for any help.
 

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