xlt-hunter
Registered User.
- Local time
- Today, 23:04
- Joined
- May 12, 2006
- Messages
- 14
Hi all, I am having a little spot of trouble with this code:
For somereason, the PrintOut function is not working (it did the other day)
Where is it going wrong?
Thanks
Private Sub cmdSend_Click()
If Me.Dirty Then
If MsgBox("Record has not been saved. " & Chr(13) & _
"Do you want to save it?", vbInformation + vbOKCancel) = vbOK Then
DoCmd.RunCommand acCmdSaveRecord
Else
Exit Sub
End If
End If
' Create a Word document from template.
Dim WordApp As Word.Application
Dim strTemplateLocation As String
' Specify location of template
strTemplateLocation = "C:\MailMerge\SSA.dot"
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
End If
On Error GoTo ErrHandler
WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
' Replace each bookmark with field contents.
With WordApp.Selection
.Goto what:=wdGoToBookmark, Name:="FirstName"
.TypeText ([FirstName])
.Goto what:=wdGoToBookmark, Name:="Name"
.TypeText [FirstName]
.Goto what:=wdGoToBookmark, Name:="Supplier"
.TypeText [Supplier]
.Goto what:=wdGoToBookmark, Name:="Address"
.TypeText [Address]
.Goto what:=wdGoToBookmark, Name:="City"
If IsNull(City) Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [City]
End If
.Goto what:=wdGoToBookmark, Name:="State"
If IsNull(State) Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [State]
End If
.Goto what:=wdGoToBookmark, Name:="Postcode"
If IsNull(PostCode) Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [PostCode]
End If
.Goto what:=wdGoToBookmark, Name:="Country"
' If recipient in own country, no need to state country in letter.
If IsNull(Country) Or Country = "United Kingdom" Then
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
Else
.TypeText [Country]
End If
.Goto what:=wdGoToBookmark, Name:="Name"
.TypeText [FirstName]
End With
DoEvents
WordApp.Activate
WordApp.PrintOut
Set WordApp = Nothing
Exit Sub
ErrHandler:
Set WordApp = Nothing
End Sub
For somereason, the PrintOut function is not working (it did the other day)
Where is it going wrong?
Thanks