Export to word template using VBA does not work

Mwam

Registered User.
Local time
Yesterday, 23:28
Joined
Aug 28, 2015
Messages
11
Hi,

I would like to export a form entry to a word template. I have VBA code connected to a command button, however, although a new word document opens upon execution, the fields are not populated (the word document remains empty). Please advise!

here is my code:

Private Sub Command694_Click()

Dim WordApp As Word.Application
Dim doc As Word.Document
On Error Resume Next
Error.Clear

Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = New Word.Application
WordApp.Visible = True
End If
Set doc = WordApp.Documents.Open("path removed for anonymity", , True)
With doc
.FormFields("fldProjectName").Result = Me.ProjectName
.FormFields("fldProjectDetail").Result = Me.ProjectDetail

End With
WordApp.Visible = True
WordApp.Activate

Set doc = Nothing
Set WordApp = Nothing

End Sub
 
put a breakline on :
.FormFields("fldProjectName").Result = Me.ProjectName

hover cursor over Me.ProjectName and then Me.ProjectDetail
are those values showing correctly,
then
on the word doc:
is the fieldname actually called :fldProjectName
and fldProjectDetail
?
 
Thank you Ranman256 for your response.

I apologize, I am still an Access amateur. What does breakline mean? also If I move my cursor over Me.ProjectName nothing happens. and Yes the fieldnames in the word document is corrcet.

Thanks again.
 
Comment out the error handling until your code runs perfect.
To do so, place a ' in front of the two code lines below:
Code:
[SIZE=4][B][COLOR=Red]'[/COLOR][/B][/SIZE]On Error Resume Next
[SIZE=4][B][COLOR=Red]'[/COLOR][/B][/SIZE]Error.Clear
 

Users who are viewing this thread

Back
Top Bottom