I am having a hard time trying to get a form and subform to populate a prebuilt word document. The main form is pretty simple and I have that functioning correctly using bookmarks. The subform is a datasheet & I am able to get the top line only to populate bookmarks.
The main form contains patient contact info and the subform contains an inventory datasheet with fields such as Description, Serial Number, Quantity, Etc.
Ideally I'd like the subform to populate a table in word that already has the columns setup and will add the appropriate number of rows as needed, based on the number of records in the datasheet.
I am using the following code, although I have trued adding some loop statements I have found online to no avail, so I removed the....Any help would be greatly appreciated...
Option Compare Database
Private Sub cmdPrint_Click()
'Print customer slip for current customer.
Dim appWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn't open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn't open, create a new instance of Word.
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Open("C:\Docs\InvSheet.docx", , True)
With doc
.FormFields("Name").Result = Me!Name
.FormFields("Room").Result = Me!Room
.FormFields("MoveInDate").Result = Me!MoveInDate
.FormFields("RESIDENTINVENTORYID").Result = subfMoveInInventory!RESIDENTINVENTORYID
.FormFields("ResidentID").Result = subfMoveInInventory!ResidentId
.FormFields("PropertyItem").Result = subfMoveInInventory!PropertyItem
.FormFields("Serial").Result = subfMoveInInventory!Serial
.FormFields("Quanty").Result = subfMoveInInventory!Quanty
.FormFields("DisposalDate").Result = subfMoveInInventory!DisposalDate
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub