Jean,
Thanks for the "Sanity-Check" -- somehow, the default view for my WORD
application changed from "Print Layout" to "Web Layout" -- that's what
caused my Header/Footer not to show -- is it Friday yet?
While chasing that gremlin, I discovered that when using the FormField
method I wasn't able to print the data -- the data showed in the FormFields,
but when I tried to print, the data disappeared. I decided to use the
BookMark Method (below) -- which NOW prints my Master Form data just fine --
I'm still stuck on getting the data from my Sub-Form to print -- could you
step me through your suggestion (RE: Now, any of the sub-form sub, as long
as they are in the same module as the master form sub, can use that document
object)
====================================================================
Option Compare Database
Option Explicit
Private docForm As Word.Document
============================
'My Print Sub
Private Sub cmdPrintInvoice_Click()
On Error GoTo Err_Handler
Dim strTemplateDoc As String
strTemplateDoc = CurrentFolder() & "Product1.dot"
If Not IsNull(Me!ProductNumber) Then
' ensure record is saved
'RunCommand acCmdSaveRecord
CreateMyInvoice strTemplateDoc
Else
MsgBox "No current record.", vbInformation, "Create Invoice"
End If
Exit_here:
Exit Sub
Err_Handler:
MsgBox Err.Description & " (" & Err.Number & ")", vbExclamation, "Error"
Resume Exit_here
'Jean I need to modify the following code to get it to print in my NEW
document -- could you walk me through the step to modify this portion
please?
On Error GoTo Err_Command83_Click
If docForm Is Nothing Then
MsgBox "You must first use the master form to create a document"
Dim stDocName As String
Dim MyForm As Form
stDocName = "PrintDetails"
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
DoCmd.PrintOut
DoCmd.SelectObject acForm, MyForm.Name, False
Exit_Command83_Click:
Exit Sub
Err_Command83_Click:
MsgBox Err.Description
Resume Exit_Command83_Click
End If
Set docForm = Nothing
End Sub
================================
'My Module to Create My Invoice
Sub CreateMyInvoice(strTemplate As String)
' Opens a document in Word and inserts values from
' current record at bookmarks in Word document.
' Accepts: path to Word template file - String
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim frm As Form
Dim strAddress As String
' return reference to form
Set frm = Forms!Addresses
' if Word open return reference to it
' else establish reference to it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = CreateObject("Word.Application")
End If
AppActivate "Microsoft Word"
On Error GoTo Err_Handler
' open Word document in maximised window
objWord.Visible = True
Set objDoc = objWord.Documents.Add(strTemplate)
'objWord.WindowState = wdWindowStateMaximize
' insert text at bookmarks, getting values from form
InsertAtBookmarks objWord, objDoc, "CompanyName", frm!CompanyName
'InsertAtBookmarks objWord, objDoc, "Address1", frm!Address1
strAddress = (frm!Address1 + vbCrLf) & (frm!Address2 + vbCrLf) & _
(frm!City + "," + " ") & (frm!Region + vbCrLf) & frm!PostalCode
InsertAtBookmarks objWord, objDoc, "Address1", strAddress
InsertAtBookmarks objWord, objDoc, "SalesRep", frm!SalesRep
InsertAtBookmarks objWord, objDoc, "Term", frm!Term
InsertAtBookmarks objWord, objDoc, "Price", frm!Price
InsertAtBookmarks objWord, objDoc, "DeliverCost", frm!DeliveryCost
Set objDoc = Nothing
Set objWord = Nothing
Exit_here:
On Error GoTo 0
Exit Sub
Err_Handler:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume Exit_here
End Sub
Thank you for all your patience and assistance
Shane
> There is something else going on here. Just creating a document from a
> template will not cause headers/footers from being changed or wiped out
> entirely.
>
> Make sure you are only creating a document from a template, that your are
> using the right template and that your code does not do anything funky
> with the headers/footers.
>
> Try debugging step by step to see when the headers/footers disappear, the
> you will know which line of code creates this situation and you will be
> able to fix it.
>
> --
>
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> (E-Mail Removed)ISTOO
> Word MVP site: http://www.word.mvps.org
>