Private Sub Command82_Click()
Dim objWord As Word.Application
Dim strFilePath As String
Dim strSupplier, strSupAddress1, strSupAddress2, strSupAddress3 As String
Dim strAttention, strSupFirstName As String
Dim strSpAddress1, strSpAddress2, strSpAddress3 As String
Dim strSpFirstName As String
Dim lngSupplierID, lngSponsorID As Long
Dim strCommunication, strProduct, strSponsor, strSponsor2 As String
Dim dtDated As Date, strDated As String
Dim lngARTG1, lngARTG2, lngARTG3, lngARTG4, lngARTG5, lngARTG6, lngARTG7, lngARTG8, lngARTG9 As Long
Dim strPIName1, strPIName2, strPIName3, strPIName4, strPIName5, strPIName6, strPIName7, strPIName8, strPIName9 As String
Dim strPlural, strPlural2, strPlural3, strPlural4, strPlural5, strProductSponsorID As String
Dim strSaveName As String
Dim strPINumbers As String
Dim strPICount1 As String, strPICount2 As String
If IsNull(Me.Communication) Then
fred = MsgBox("The type of communication must be entered.", vbOKOnly, "Missing Data")
Exit Sub
End If
If IsNull(Me.Dated) Then
fred = MsgBox("The Date of the communication must be entered.", vbOKOnly, "Missing Data")
Exit Sub
End If
If IsNull(Me.Product) Then
fred = MsgBox("The Product Name or a general description must be entered.", vbOKOnly, "Missing Data")
Exit Sub
End If
'place values from current record into Supplier Letter
strSupplier = Me.Supplier
strSupAddress1 = Nz(Me.Address1)
strSupAddress2 = Nz(Me.Address2)
strSupAddress3 = Nz(Me.Address3)
strAttention = Nz(Me.Attention)
strSupFirstName = Nz(Me.supFirstName)
strSpAddress1 = Nz(Me.spAddress1)
strSpAddress2 = Nz(Me.spAddress2)
strSpAddress3 = Nz(Me.spAddress3)
strSpFirstName = Nz(Me.spFirstName)
lngSupplierID = Nz(Me.SupplierID)
lngSponsorID = Nz(Me.SponsorID)
strCommunication = Nz(Me.Communication)
dtDated = Nz(Me.Dated)
strDated = CStr(Format(dtDated, "d mmmm yyyy"))
strProduct = Nz(Me.Product)
If Me.Sponsor = Me.Supplier Then
strSponsor = "your company"
Else
strSponsor = Nz(Me.Sponsor)
End If
strSponsorID = Nz(Me.SponsorID)
If strSponsorID = "" Then
strProductSponsorID = strProduct ' changed 24 July 2006
Else
strProductSponsorID = strProduct & " sponsored by " & strSponsor & " (Client ID: " & strSponsorID & ")"
End If
lngARTG1 = Nz(Me.ARTG1)
lngARTG2 = Nz(Me.ARTG2)
lngARTG3 = Nz(Me.ARTG3)
lngARTG4 = Nz(Me.ARTG4)
lngARTG5 = Nz(Me.ARTG5)
lngARTG6 = Nz(Me.ARTG6)
lngARTG7 = Nz(Me.ARTG7)
lngARTG8 = Nz(Me.ARTG8)
lngARTG9 = Nz(Me.ARTG9)
strPIName1 = Nz(Me.PIName1)
strPIName2 = Nz(Me.PIName2)
strPIName3 = Nz(Me.PIName3)
strPIName4 = Nz(Me.PIName4)
strPIName5 = Nz(Me.PIName5)
strPIName6 = Nz(Me.PIName6)
strPIName7 = Nz(Me.PIName7)
strPIName8 = Nz(Me.PIName8)
strPIName9 = Nz(Me.PIName9)
If lngARTG2 = 0 Then
strPlural = "a New Proprietary Ingredient"
strPlural2 = "ingredient is"
strPlural3 = "has"
strPlural4 = "This Proprietary Ingredient has"
strPlural4a = "This Proprietary Ingredient is"
strPlural5 = "ingredient is"
strPICount1 = "This Proprietary Ingredient has"
strPICount2 = "this Proprietary Ingredient"
Else
strPlural = "New Proprietary Ingredients"
strPlural2 = "ingredients are"
strPlural3 = "have"
strPlural4 = "These Proprietary Ingredients have"
strPlural4a = "These Proprietary Ingredients are"
strPlural5 = "ingredients are"
strPICount1 = "These Proprietary Ingredients have"
strPICount2 = "these Proprietary Ingredients"
End If
' build string of PI Numbers
strPINumbers = Me.ARTG1
If Not IsNull(Me.ARTG2) Then
strPINumbers = strPINumbers & " " & Me.ARTG2
End If
If Not IsNull(Me.ARTG3) Then
strPINumbers = strPINumbers & " " & Me.ARTG3
End If
If Not IsNull(Me.ARTG4) Then
strPINumbers = strPINumbers & " " & Me.ARTG4
End If
If Not IsNull(Me.ARTG5) Then
strPINumbers = strPINumbers & " " & Me.ARTG5
End If
If Not IsNull(Me.ARTG6) Then
strPINumbers = strPINumbers & " " & Me.ARTG6
End If
If Not IsNull(Me.ARTG7) Then
strPINumbers = strPINumbers & " " & Me.ARTG7
End If
If Not IsNull(Me.ARTG8) Then
strPINumbers = strPINumbers & " " & Me.ARTG8
End If
If Not IsNull(Me.ARTG9) Then
strPINumbers = strPINumbers & " " & Me.ARTG9
End If
'Start Microsoft Word 2003
On Error GoTo ErrorHandler
' Supplier Letter
'production path and filename
strSaveName = "S:/CO/TGA/COMP/ELFLIST/listing/Prop Ingredient Letters/PI " & strPINumbers & " Supplier " & Me.Combo74
'testing and development path and filename
'strSaveName = "D:/Projects/PILetters/PI " & strPINumbers & " Supplier " & Me.Combo74
Set objWord = GetObject(, "Word.Application")
'Set objWord = CreateObject("Word.Application") ' original
With objWord
' Make the application visible.
.Visible = True
' Open the document.
'production path and filename
'.Documents.Open ("D:\Projects\Prop Ingredient Letters\PILetters\Supplier PI Letter.doc")
'testing and development path and filename
.Documents.Open ("S:\CO\TGA\COMP\ELFLIST\listing\Prop Ingredient Letters\PILetters\Supplier PI Letter.doc")
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End With
With objWord.Selection
.GoTo What:=wdGoToBookmark, Name:="Supplier"
.TypeText Text:=strSupplier
.GoTo What:=wdGoToBookmark, Name:="Address1"
.TypeText Text:=strSupAddress1
.GoTo What:=wdGoToBookmark, Name:="Address2"
.TypeText Text:=strSupAddress2
.GoTo What:=wdGoToBookmark, Name:="Address3"
.TypeText Text:=strSupAddress3
.GoTo What:=wdGoToBookmark, Name:="Attention"
.TypeText Text:=strAttention
.GoTo What:=wdGoToBookmark, Name:="SupplierID"
.TypeText Text:=lngSupplierID
.GoTo What:=wdGoToBookmark, Name:="Product"
.TypeText Text:=strProduct
.GoTo What:=wdGoToBookmark, Name:="Sponsor"
If Len(strSponsorID) < 2 Then
Else
strSponsor2 = "sponsored by " & strSponsor
End If
.TypeText Text:=strSponsor2
.GoTo What:=wdGoToBookmark, Name:="SponsorID"
.TypeText Text:=strSponsorID
.GoTo What:=wdGoToBookmark, Name:="SupFirstName"
.TypeText Text:=strSupFirstName
.GoTo What:=wdGoToBookmark, Name:="Communication"
.TypeText Text:=strCommunication
.GoTo What:=wdGoToBookmark, Name:="Dated"
.TypeText Text:=strDated
.GoTo What:=wdGoToBookmark, Name:="ifPlural1"
.TypeText Text:=strPlural
.GoTo What:=wdGoToBookmark, Name:="ifPlural4"
.TypeText Text:=strPlural4a
.GoTo What:=wdGoToBookmark, Name:="ProductSponsorID"
.TypeText Text:=strProductSponsorID
.GoTo What:=wdGoToBookmark, Name:="ifPlural2"
.TypeText Text:=strPlural2
.GoTo What:=wdGoToBookmark, Name:="ifPlural3"
.TypeText Text:=strPlural3
.GoTo What:=wdGoToBookmark, Name:="ARTG1"
.TypeText Text:=lngARTG1
.GoTo What:=wdGoToBookmark, Name:="PIName1"
.TypeText Text:=strPIName1
If lngARTG2 <> 0 Then ' 24 July 06 ARTGn changed to lngARTGn
.GoTo What:=wdGoToBookmark, Name:="ARTG2"
.TypeText Text:=lngARTG2
.GoTo What:=wdGoToBookmark, Name:="PIName2"
.TypeText Text:=strPIName2
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG2"
Selection.Rows.Delete
End If
If lngARTG3 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG3"
.TypeText Text:=lngARTG3
.GoTo What:=wdGoToBookmark, Name:="PIName3"
.TypeText Text:=strPIName3
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG3"
Selection.Rows.Delete
End If
If lngARTG4 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG4"
.TypeText Text:=lngARTG4
.GoTo What:=wdGoToBookmark, Name:="PIName4"
.TypeText Text:=strPIName4
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG4"
Selection.Rows.Delete
End If
If lngARTG5 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG5"
.TypeText Text:=lngARTG5
.GoTo What:=wdGoToBookmark, Name:="PIName5"
.TypeText Text:=strPIName5
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG5"
Selection.Rows.Delete
End If
If lngARTG6 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG6"
.TypeText Text:=lngARTG6
.GoTo What:=wdGoToBookmark, Name:="PIName6"
.TypeText Text:=strPIName6
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG6"
Selection.Rows.Delete
End If
If lngARTG7 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG7"
.TypeText Text:=lngARTG7
.GoTo What:=wdGoToBookmark, Name:="PIName7"
.TypeText Text:=strPIName7
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG7"
Selection.Rows.Delete
End If
If lngARTG8 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG8"
.TypeText Text:=lngARTG8
.GoTo What:=wdGoToBookmark, Name:="PIName8"
.TypeText Text:=strPIName8
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG8"
Selection.Rows.Delete
End If
If lngARTG9 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG9"
.TypeText Text:=lngARTG9
.GoTo What:=wdGoToBookmark, Name:="PIName9"
.TypeText Text:=strPIName9
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG9"
Selection.Rows.Delete
End If
.GoTo What:=wdGoToBookmark, Name:="Supplier2"
.TypeText Text:=strSupplier
.GoTo What:=wdGoToBookmark, Name:="SupplierID2"
.TypeText Text:=lngSupplierID
.GoTo What:=wdGoToBookmark, Name:="PICount1"
.TypeText Text:=strPICount1
.GoTo What:=wdGoToBookmark, Name:="PICount2"
.TypeText Text:=strPICount2
.GoTo What:=wdGoToBookmark, Name:="letterDate"
.TypeText Text:=CStr(Format(Now, "d mmmm yyyy"))
End With
ActiveDocument.SaveAs FileName:=strSaveName, FileFormat:=wdFormatDocument
'Sponsor Letter
If IsNull(Me.Sponsor) Then
If IsNull(Me.Agent) Then
Exit Sub
End If
End If
If Me.Supplier <> "" Then
'production path and filename
strSaveName = "S:/CO/TGA/COMP/ELFLIST/listing/Prop Ingredient Letters/PI " & strPINumbers & " Sponsor " & Me.Combo76
'testing and development path and filename
'strSaveName = "D:/Projects/PILetters/PI " & strPINumbers & " Sponsor " & Me.Combo76
If Me.Supplier = Me.Sponsor Then
Exit Sub
End If
If Not IsNull(Me.Sponsor) Then
With objWord
' Make the application visible.
.Visible = True
' Open the document.
'production path and filename
.Documents.Open ("S:\CO\TGA\COMP\ELFLIST\listing\Prop Ingredient Letters\PILetters\Sponsor PI Letter.doc")
'testing and development path and filename
'.Documents.Open ("D:\Projects\PILetters\Sponsor PI Letter.doc")
End With
strAttention = Nz(Me.spAttention)
With objWord.Selection
.GoTo What:=wdGoToBookmark, Name:="Sponsor"
.TypeText Text:=strSponsor
.GoTo What:=wdGoToBookmark, Name:="spAddress1"
.TypeText Text:=strSpAddress1
.GoTo What:=wdGoToBookmark, Name:="spAddress2"
.TypeText Text:=strSpAddress2
.GoTo What:=wdGoToBookmark, Name:="spAddress3"
.TypeText Text:=strSpAddress3
.GoTo What:=wdGoToBookmark, Name:="Attention"
.TypeText Text:=strAttention
.GoTo What:=wdGoToBookmark, Name:="SupplierID"
.TypeText Text:=lngSponsorID
.GoTo What:=wdGoToBookmark, Name:="Supplier"
.TypeText Text:=strSupplier
.GoTo What:=wdGoToBookmark, Name:="Product"
.TypeText Text:=strProduct
.GoTo What:=wdGoToBookmark, Name:="spFirstName"
.TypeText Text:=strSpFirstName
.GoTo What:=wdGoToBookmark, Name:="Supplier2"
.TypeText Text:=strSupplier
.GoTo What:=wdGoToBookmark, Name:="SupplierID2"
.TypeText Text:=lngSupplierID
.GoTo What:=wdGoToBookmark, Name:="ifPlural2"
.TypeText Text:=strPlural5
.GoTo What:=wdGoToBookmark, Name:="Product2"
.TypeText Text:=strProduct
.GoTo What:=wdGoToBookmark, Name:="Entered"
.TypeText Text:=strPlural4
.GoTo What:=wdGoToBookmark, Name:="ARTG1"
.TypeText Text:=lngARTG1
.GoTo What:=wdGoToBookmark, Name:="PIName1"
.TypeText Text:=strPIName1
If ARTG2 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG2"
.TypeText Text:=lngARTG2
.GoTo What:=wdGoToBookmark, Name:="PIName2"
.TypeText Text:=strPIName2
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG2"
Selection.Rows.Delete
End If
If ARTG3 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG3"
.TypeText Text:=lngARTG3
.GoTo What:=wdGoToBookmark, Name:="PIName3"
.TypeText Text:=strPIName3
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG3"
Selection.Rows.Delete
End If
If ARTG4 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG4"
.TypeText Text:=lngARTG4
.GoTo What:=wdGoToBookmark, Name:="PIName4"
.TypeText Text:=strPIName4
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG4"
Selection.Rows.Delete
End If
If ARTG5 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG5"
.TypeText Text:=lngARTG5
.GoTo What:=wdGoToBookmark, Name:="PIName5"
.TypeText Text:=strPIName5
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG5"
Selection.Rows.Delete
End If
If ARTG6 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG6"
.TypeText Text:=lngARTG6
.GoTo What:=wdGoToBookmark, Name:="PIName6"
.TypeText Text:=strPIName6
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG6"
Selection.Rows.Delete
End If
If ARTG7 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG7"
.TypeText Text:=lngARTG7
.GoTo What:=wdGoToBookmark, Name:="PIName7"
.TypeText Text:=strPIName7
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG7"
Selection.Rows.Delete
End If
If ARTG8 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG8"
.TypeText Text:=lngARTG8
.GoTo What:=wdGoToBookmark, Name:="PIName8"
.TypeText Text:=strPIName8
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG8"
Selection.Rows.Delete
End If
If ARTG9 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG9"
.TypeText Text:=lngARTG9
.GoTo What:=wdGoToBookmark, Name:="PIName9"
.TypeText Text:=strPIName9
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG9"
Selection.Rows.Delete
End If
.GoTo What:=wdGoToBookmark, Name:="Supplier3"
.TypeText Text:=strSupplier
.GoTo What:=wdGoToBookmark, Name:="SupplierID3"
.TypeText Text:=lngSupplierID
.GoTo What:=wdGoToBookmark, Name:="PICount1"
.TypeText Text:=strPICount1
.GoTo What:=wdGoToBookmark, Name:="PICount2"
.TypeText Text:=strPICount2
.GoTo What:=wdGoToBookmark, Name:="letterDate"
.TypeText Text:=CStr(Format(Now, "d mmmm yyyy"))
End With
End If
ActiveDocument.SaveAs FileName:=strSaveName, FileFormat:=wdFormatDocument
End If
'Agent Letter
If Me.txtAgent <> "" Then
strAgent = Me.txtAgent
strAgAddress1 = Me.txtAgAddress1
strAgAddress2 = Me.txtAgAddress2
strAgAddress3 = Me.txtAgAddress3
strAgAttention = Me.txtAgAttention
strAgFirstName = Me.txtAgFirstName
strAgentID = Me.Combo92
strSupplier = Me.Supplier
strSupplier2 = Me.Supplier
strSupplierID = Me.Combo74
strSponsor = Me.Sponsor
If strSponsorID = "" Then
strProductSponsorID = ""
Else
strProductSponsorID = strProduct & " sponsored by " & strSponsor & " (Client ID: " & strSponsorID & ")"
End If
'production path and filename
strSaveName = "S:/CO/TGA/COMP/ELFLIST/listing/Prop Ingredient Letters/PI " & strPINumbers & " Agent " & Me.Combo92
'testing and development path and filename
'strSaveName = "D:/Projects/PILetters/PI " & strPINumbers & " Agent " & Me.Combo92
With objWord
' Make the application visible.
.Visible = True
' Open the document.
'production path and filename
.Documents.Open ("S:\CO\TGA\COMP\ELFLIST\listing\Prop Ingredient Letters\PILetters\Agent PI Letter.doc")
'testing and development path and filename
'.Documents.Open ("D:\Projects\PILetters\Agent PI Letter.doc")
End With
With objWord.Selection
.GoTo What:=wdGoToBookmark, Name:="Agent"
.TypeText Text:=strAgent
.GoTo What:=wdGoToBookmark, Name:="agAddress1"
.TypeText Text:=strAgAddress1
.GoTo What:=wdGoToBookmark, Name:="agAddress2"
.TypeText Text:=strAgAddress2
.GoTo What:=wdGoToBookmark, Name:="agAddress3"
.TypeText Text:=strAgAddress3
.GoTo What:=wdGoToBookmark, Name:="agAttention"
.TypeText Text:=strAttention
.GoTo What:=wdGoToBookmark, Name:="AgentID"
.TypeText Text:=strAgentID
.GoTo What:=wdGoToBookmark, Name:="Supplier"
.TypeText Text:=strSupplier
.GoTo What:=wdGoToBookmark, Name:="agFirstName"
.TypeText Text:=strAgFirstName
.GoTo What:=wdGoToBookmark, Name:="Supplier2"
.TypeText Text:=strSupplier
.GoTo What:=wdGoToBookmark, Name:="SupplierID2"
.TypeText Text:=lngSupplierID
.GoTo What:=wdGoToBookmark, Name:="ifPlural2"
.TypeText Text:=strPlural2
.GoTo What:=wdGoToBookmark, Name:="ProductSponsorID"
If Len(strSponsorID) < 2 Then
Else
strSponsor2 = "sponsored by " & strSponsor
End If
.TypeText Text:=strProductSponsorID
.GoTo What:=wdGoToBookmark, Name:="ifPlural"
.TypeText Text:=strPlural4
.GoTo What:=wdGoToBookmark, Name:="ARTG1"
.TypeText Text:=lngARTG1
.GoTo What:=wdGoToBookmark, Name:="PIName1"
.TypeText Text:=strPIName1
If ARTG2 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG2"
.TypeText Text:=lngARTG2
.GoTo What:=wdGoToBookmark, Name:="PIName2"
.TypeText Text:=strPIName2
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG2"
Selection.Rows.Delete
End If
If ARTG3 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG3"
.TypeText Text:=lngARTG3
.GoTo What:=wdGoToBookmark, Name:="PIName3"
.TypeText Text:=strPIName3
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG3"
Selection.Rows.Delete
End If
If ARTG4 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG4"
.TypeText Text:=lngARTG4
.GoTo What:=wdGoToBookmark, Name:="PIName4"
.TypeText Text:=strPIName4
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG4"
Selection.Rows.Delete
End If
If ARTG5 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG5"
.TypeText Text:=lngARTG5
.GoTo What:=wdGoToBookmark, Name:="PIName5"
.TypeText Text:=strPIName5
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG5"
Selection.Rows.Delete
End If
If ARTG6 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG6"
.TypeText Text:=lngARTG6
.GoTo What:=wdGoToBookmark, Name:="PIName6"
.TypeText Text:=strPIName6
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG6"
Selection.Rows.Delete
End If
If ARTG7 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG7"
.TypeText Text:=lngARTG7
.GoTo What:=wdGoToBookmark, Name:="PIName7"
.TypeText Text:=strPIName7
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG7"
Selection.Rows.Delete
End If
If ARTG8 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG8"
.TypeText Text:=lngARTG8
.GoTo What:=wdGoToBookmark, Name:="PIName8"
.TypeText Text:=strPIName8
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG8"
Selection.Rows.Delete
End If
If ARTG9 <> 0 Then
.GoTo What:=wdGoToBookmark, Name:="ARTG9"
.TypeText Text:=lngARTG9
.GoTo What:=wdGoToBookmark, Name:="PIName9"
.TypeText Text:=strPIName9
Else
Selection.GoTo What:=wdGoToBookmark, Name:="ARTG9"
Selection.Rows.Delete
End If
.GoTo What:=wdGoToBookmark, Name:="Supplier3"
.TypeText Text:=strSupplier
.GoTo What:=wdGoToBookmark, Name:="SupplierID3"
.TypeText Text:=lngSupplierID
.GoTo What:=wdGoToBookmark, Name:="PICount1"
.TypeText Text:=strPICount1
.GoTo What:=wdGoToBookmark, Name:="PICount2"
.TypeText Text:=strPICount2
.GoTo What:=wdGoToBookmark, Name:="letterDate"
.TypeText Text:=CStr(Format(Now, "d mmmm yyyy"))
End With
ActiveDocument.SaveAs FileName:=strSaveName, FileFormat:=wdFormatDocument
End If
ErrorHandlerExit:
Set objWord = Nothing
Exit Sub
ErrorHandler:
If Err = 429 Then
'Word not running
Set objWord = CreateObject("Word.Application")
Resume Next
ElseIf Err = 462 Then
Set objWord = GetObject(, "Word.Application")
Resume Next
Else
MsgBox "Error No: " & Err.Number & " Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub