Hi
I have used the ms example to export the data from a form.
When I run the procedure the word doc opens but the data is not there, just the original bookmarks.
Any suggestions would be great.
Here is the code.
Thanks
Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err
Dim objWord As Word.Application
'Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application")
With objWord
'Make the application visible.
.Visible = True
'Open the document.
.Documents.Open ("C:\MyMerge.doc")
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("DateofComment").Select
.Selection.Text = (CStr(Forms!forProject!DateofComment))
.ActiveDocument.Bookmarks("Comments").Select
.Selection.Text = (CStr(Forms!forProject!Comment))
.ActiveDocument.Bookmarks("Action").Select
.Selection.Text = (CStr(Forms!forProject!Action))
.ActiveDocument.Bookmarks("ActionByDate").Select
.Selection.Text = (CStr(Forms!forProject!ActionByDate))
.ActiveDocument.Bookmarks("ByWhom").Select
.Selection.Text = (CStr(Forms!forProject!ByWhom))
End With
'Print the document in the foreground so Microsoft Word will not close
'until the document finishes printing.
objWord.ActiveDocument.PrintOut Background:=False
'Close the document without saving changes.
objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Quit Microsoft Word and release the object variable.
objWord.Quit
Set objWord = Nothing
Exit Sub
MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub
I have used the ms example to export the data from a form.
When I run the procedure the word doc opens but the data is not there, just the original bookmarks.
Any suggestions would be great.
Here is the code.
Thanks
Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err
Dim objWord As Word.Application
'Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application")
With objWord
'Make the application visible.
.Visible = True
'Open the document.
.Documents.Open ("C:\MyMerge.doc")
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("DateofComment").Select
.Selection.Text = (CStr(Forms!forProject!DateofComment))
.ActiveDocument.Bookmarks("Comments").Select
.Selection.Text = (CStr(Forms!forProject!Comment))
.ActiveDocument.Bookmarks("Action").Select
.Selection.Text = (CStr(Forms!forProject!Action))
.ActiveDocument.Bookmarks("ActionByDate").Select
.Selection.Text = (CStr(Forms!forProject!ActionByDate))
.ActiveDocument.Bookmarks("ByWhom").Select
.Selection.Text = (CStr(Forms!forProject!ByWhom))
End With
'Print the document in the foreground so Microsoft Word will not close
'until the document finishes printing.
objWord.ActiveDocument.PrintOut Background:=False
'Close the document without saving changes.
objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Quit Microsoft Word and release the object variable.
objWord.Quit
Set objWord = Nothing
Exit Sub
MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub