vba - Passing data from Word bookmark to field in Access form - Stack Overflow

PHOTO EMBED

Mon Jul 10 2023 13:53:10 GMT+0000 (Coordinated Universal Time)

Saved by @paulbarry

    Function fillWordForm()

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

On Error Resume Next
Error.Clear

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"
Else
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
appWord.Active
End With
Set doc = Nothing
Set appWord = Nothing

End If
End Function
content_copyCOPY

https://stackoverflow.com/questions/59262576/passing-data-from-word-bookmark-to-field-in-access-form