I'm trying to pass data from a form with a subform into a microsoft word document, form and subform in this image:
I have code for passing the form data, but I'm not sure how I reference or request the data from the subform? Ideally the string returned would contain every piece of subform data for the referenced column.
What I have so far is as follows:
Private Sub Command90_Click()
Dim objWRD As Word.Application
Dim objDoc As Word.Document
Set objWRD = CreateObject("Word.Application")
objWRD.Visible = True
objWRD.Activate
Set objDoc = objWRD.Documents.Add("C:\WordTemplate.dot", , , True)
Set objRange = objDoc.Bookmarks("AccountCode").Range
objRange.Text = "" & Me.[Account Code / Project Number].Column(1)
Set objRange = objDoc.Bookmarks("Consignto").Range
objRange.Text = "" & Me.[Consign To]
End Sub
I did try adding this following code, but of course it only returns the first record of the subform, whereas I want it to return all of the subform price records that are displayed:
Set objRange = objDoc.Bookmarks("Price").Range
objRange.Text = "" & Me.[Order Details].Form.[Price]
Edit:
Closest I've come to a solution is this:
Private Sub Command90_Click()
Dim rst1 As DAO.Recordset
MsgBox "" & Me.[Order Details].Form.RecordsetClone.RecordCount
Set rst1 = Me.[Order Details].Form.RecordsetClone
rst1.MoveFirst
Do Until rst1.EOF
MsgBox "" & rst1.[Price]
rst1.MoveNext
rst1.Close
Loop
End Sub
MsgBox "" & rst1.[Price] is wrong and MsgBox "" & Me.[Order Details].Form.[Price] just gives the first value multiple times and doesn't appear to move down rows