Hi there,
I am having trouble getting all my records to be placed into my WORD document from my ACCESS form. I have a form with a subform displayed and a control button that executes a macro. The macro just says runcode MergeToWord and the following is my VBA code:
CODE:
Sub MergeToWord()
On Error GoTo MergeToWord_err
Dim objWord As Object
Set objWord = Nothing
Set objWord = CreateObject("Word.application")
objWord.Documents.Open "C:\Documents and Settings\messersmithm\My Documents\LOAR Creation\LOARtemp.doc"
objWord.Visible = True
With objWord.ActiveDocument.Bookmarks
.Item("Report_No").Range.Text = Forms![LOAR Log Form]![Report_Number]
.Item("Rev_No").Range.Text = Forms![LOAR Log Form]![Rev]
.Item("Rev_Date").Range.Text = Forms![LOAR Log Form]![Rev_Date]
.Item("Model_No").Range.Text = Forms![LOAR Log Form]![Model]
.Item("Serial_No").Range.Text = Forms![LOAR Log Form]![Serial_Number]
.Item("Sub_Rev").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Revision]
.Item("Sub_Date").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Change_Date]
.Item("Sub_Desc").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Change_Description]
.Item("Sub_By").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Submitted_By]
.Item("Dept_Code").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Department_Code]
End With
objWord.ActiveDocument.SaveAs "C:\Documents and Settings\messersmithm\My Documents\LOAR Creation\LOAR.doc"
objWord.ActiveDocument.Close
objWord.Quit
Set objWord = Nothing
MergeToWord_exit:
Exit Sub
MergeToWord_err:
MsgBox (Err.Description)
objWord.ActiveDocument.SaveAs "C:\Documents and Settings\messersmithm\My Documents\LOAR Creation\LOAR.doc"
objWord.ActiveDocument.Close
objWord.Quit
Set objWord = Nothing
GoTo MergeToWord_exit
End Sub
END CODE:
The data from the main form and the first record from the subform appear in the word document just fine but the additional records on the subform do not. I do not know how to tell it to loop until they are all placed in the document. I tried a Do Until .EOF but it did not work and messed everything up.
Thanks so much,
DeeDee