code to force print layout

hbaggs

Registered User.
Local time
Today, 09:21
Joined
Feb 5, 2004
Messages
39
I use Access to merge a query with a Word 2003 document then save it ready for emailing. However as the clients receive the document via email the view appears to be "normal". Is there a way I can force Print Layout by saving the document in that Print Layout view by code after the merge is complete and before it is emailed?
 
I assume you mean the Word document should be in Print Layout. This will do it, assuming you have a Word Application object and a Word Document object defined. After declaring the Word Document object, you need to set the Word Document object like this:

WordDocObject.ActiveWindow.View = wdPrintView

If you're not using a Word Application object in conjunction with a Word Document object, I'm not sure what to tell you. (I think there might be a way to do this with macros, which you may be using, and which won't allow this level of control.)
 
Exactly what I needed

Thank you so much, this is the answer- I do appreciate your assistance
 
Almost- but not quite

I have been testing using your suggestion and with some minor change to your suggested code. However something else is wrong or the placement of the code is wrong. I paste the code underneath (but have deleted the majority of the code you do not need to see in the middle). You can see the places I have tried your suggested code

Sub ConstructVenStatement(Optional IsEmail As Boolean)
Dim objWRD As Word.Application
Dim objDoc As Word.Document
Dim stDocName As String
stDocName = "frmStatementIsComing"
Dim X As Integer
Dim SaveDoc As Boolean

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryStatementVen"
DoCmd.SetWarnings True

DoCmd.OpenForm stDocName

Set objWRD = CreateObject("Word.Application")
'objWRD.ActiveWindow.View = wdPrintView
objWRD.Visible = False
'objWRD.ActiveWindow.View = wdPrintView
'Then I have tried to put it in just before the document is saved see below

If IsEmail Then
Set objDoc = objWRD.Documents.Add(AccessDocsPath & "\Vendor Statements Email.dot", , , True)
Else
Set objDoc = objWRD.Documents.Add(AccessDocsPath & "\Vendor Statements.dot", , , True)
End If

objWRD.ScreenUpdating = False
objWRD.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
'''''''''' SEVERAL PAGES OF CODE IN HERE

objWRD.Visible = True
objWRD.ActiveDocument.MailMerge.Execute
objWRD.ActiveWindow.View = wdPrintView
objWRD.ScreenUpdating = True
DoCmd.Close
objWRD.ActiveDocument.Saved = True

SaveDoc = False
SaveDoc = IsEmail
If SaveDoc = True Then
objDoc.MailMerge.DataSource.QueryString = ""
objDoc.SaveAs CurrentProject.Path & "\VenStatEmail.Doc", , , , , , True
objDoc.Close False
Else
objDoc.Close False '<************************
End If

Set objDoc = Nothing
Set objWRD = Nothing
End Sub


Have you got any ideas of where that code should be positioned?
 

Users who are viewing this thread

Back
Top Bottom