Function fillWordForm()

Dim appWord As Object
Dim doc As Object
Dim path As String
Dim myID As String

On Error Resume Next

Set appWord = CreateObject("word.application")
If Err.Number <> 0 Then
Set appWord = New Word.Application
appWord.Visible = True
End If

path = Application.CurrentProject.path & "\H_F.docx"

If FileExists(path) = False Then
MsgBox "Template File Not Found", vbExclamation, "File Not Found"
Set doc = appWord.Documents.Add(path, , True)
myID = DLookup("ID", "Exports_imports_Table", "[ID] = " & Me.ID)
With doc
.FormFields("BookID").Result = [ID]
.FormFields("Book_BC_date").Result = Me.date_BC
.FormFields("Book_AH_date").Result = Me.date_AH
.FormFields("Book_AH_date").Result = Me.date_AH
.FormFields("BookTopic").Result = Me.topic
.FormFields("BookProjectName").Result = Me.projectName
.FormFields("BookCompanyName").Result = Me.companyName
.FormFields("BookContent").Range.Text = Me.content

'Result = Me.content

appWord.Visible = True
End With
Set doc = Nothing
Set appWord = Nothing

End If
End Function
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter