Mail Merge

Lyncroft

QPR for ever
Local time
Today, 03:00
Joined
May 18, 2002
Messages
168
I'm using this code which I found on this site to do a mail merge. Works fine. When it goes to word the screen isn't maximised. I would like to go to print preview too if possible. Any ideas?

Dim dbs As DAO.Database, rstNames As Recordset
Dim objWord As Object
Set objWord = CreateObject("Word.Application")

'switch to ms word so it won't go away when you finish.
Dim appWord As Word.Application

'DoCmd.GoToControl "FirstName"
' Start Microsoft Word 97.
Set appWord = CreateObject("Word.Application")
With appWord
' Make the application visible.
.Visible = True
' Open the document.
.Documents.Open ("c:\Media\New.doc")
' Move to each bookmark and insert text from the form.
.ActiveDocument.bookmarks("FirstName").Select
.selection.Text = (CStr(Forms!frmTest!FirstName))
.ActiveDocument.bookmarks("LastName").Select
.selection.Text = (CStr(Forms!frmTest!LastName))
End With

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
Else
MsgBox Err.Number & vbCr & Err.Description
End If
Exit Sub
End Sub
 
Whoops. Didn't have the references for Word ticked. Added code
objWord.ActiveDocument.PrintPreview
objWord.Visible = True
objWord.WindowState = wdWindowStateMaximize

Seems to work. Another few hours wasted!!!
 

Users who are viewing this thread

Back
Top Bottom