Problems with Routing slip

T

Tim Cadieux

I've got a Template to which I add a routing slip when the client hits the
Submit button. I also send a separate e-mail to one group because their
Service account will read the e-mail and add the job directly into their
work database. This Template works perfectly fine on my Machine but on a
number of other PCs, it simply shuts down when it hits the first Route
Recipient e-mail address¦

I've pasted the code belowI have a reference to Outlook 9.0 Object Library





Sub SendEnvoyer()

Static Sent As Integer



If Sent = 1 Then

MsgBox "The document has already been sent / Le document est envoyer."

Else

Call SendAsRoutingSlip

Call SendtoTrinetSolutions

MsgBox "Document sent/envoyer"

End If



Sent = 1



End Sub





Sub SendAsRoutingSlip()



With ActiveDocument

.HasRoutingSlip = True



.RoutingSlip.AddRecipient Recipient:="Services - Security
Operations/operations securite" <-- Word Simply Closes right here

.RoutingSlip.AddRecipient Recipient:="Human Res./Res. Humaines"

.RoutingSlip.AddRecipient Recipient:="Orientation Employee/employees"

.RoutingSlip.AddRecipient Recipient:="Services - Accounting
Services/Services de comptabilitiÉ"

.RoutingSlip.AddRecipient Recipient:="Services - CIMS Support/Soutien
CIMS"

.RoutingSlip.AddRecipient Recipient:="Services - Facilities/Locaux"

.RoutingSlip.AddRecipient Recipient:="Services - Library/BibliothÈque"

.RoutingSlip.AddRecipient Recipient:="Services - Mail/Courrier"

.RoutingSlip.AddRecipient Recipient:="Services - Electronic Information
Holdings/Fonds de renseignements Électroniques"

.RoutingSlip.AddRecipient Recipient:="Services - Telecommunications"

.RoutingSlip.AddRecipient Recipient:="Services - Signing Authority /
Pouvoir de signer"

.RoutingSlip.AddRecipient Recipient:="Services - Corporate Reporting
(BI)/Rapports MinistÉriels (IA)"



With .RoutingSlip

.Protect = wdAllowOnlyRevisions

.Subject = "EMPLOYEE ARRIVAL FORM - FORMULAIRE DE L'EMPLOYÉ "

.Message = ""

.Delivery = wdAllAtOnce

.ReturnWhenDone = False

.TrackStatus = False

End With

.Route

End With





End Sub



Sub SendtoTrinetSolutions()

Dim bStarted As Boolean

Dim oOutlookApp As Outlook.Application

Dim oItem As Outlook.MailItem

Dim sContent As String

Dim Lang As String, Dept As String



'Get the Document's information and store it in 1 Variable

If ActiveDocument.FormFields("check6").Result = 1 Then 'check box is
checked

Lang = "English"

ElseIf ActiveDocument.FormFields("check5").Result = 1 Then

Lang = "French"

End If



If ActiveDocument.FormFields("check7").Result = 1 Then 'check box is
checked

Dept = "Fin"

ElseIf ActiveDocument.FormFields("check8").Result = 1 Then

Dept = "TBS-SCT"

ElseIf ActiveDocument.FormFields("check9").Result = 1 Then

Dept = "PSHRMAC/AGRHFPC"

End If





sContent = "Start Date: " & (ActiveDocument.FormFields("Text24").Result) &
vbCrLf

sContent = sContent & "Last Name: " &
(ActiveDocument.FormFields("Text1").Result) & vbCrLf

sContent = sContent & "First Name: " &
(ActiveDocument.FormFields("Text15").Result) & vbCrLf

sContent = sContent & "Middle Initial: " &
(ActiveDocument.FormFields("initial").Result) & vbCrLf

sContent = sContent & "Department: " & Dept & vbCrLf

sContent = sContent & "Language: " & Lang & vbCrLf

sContent = sContent & "Branch: " &
(ActiveDocument.FormFields("Text18").Result) & vbCrLf

sContent = sContent & "Division: " &
(ActiveDocument.FormFields("Text19").Result) & vbCrLf

sContent = sContent & "Section: " &
(ActiveDocument.FormFields("Text20").Result) & vbCrLf

sContent = sContent & "Reports To: " &
(ActiveDocument.FormFields("Text23").Result) & vbCrLf

If ActiveDocument.FormFields("Text27").Result <> "" Then

sContent = sContent & "Previous Department : " &
(ActiveDocument.FormFields("Text27").Result) & vbCrLf

End If

sContent = sContent & "Comments : " &
(ActiveDocument.FormFields("Text34").Result) & vbCrLf

On Error Resume Next



'Get Outlook if it's running

Set oOutlookApp = GetObject(, "Outlook.Application")

If Err <> 0 Then

'Outlook wasn't running, start it from code

Set oOutlookApp = CreateObject("Outlook.Application")

bStarted = True

End If



'Create a new mailitem

Set oItem = oOutlookApp.CreateItem(olMailItem)



With oItem

'Set the recipient for the new email

.To = "Services - Trinet Solutions"

'Set the recipient for a copy

'.CC = "(e-mail address removed)"

'Set the subject

.Subject = "EMPLOYEE ARRIVAL FORM - FORMULAIRE DE L'EMPLOYÉ"

'The content of the document is used as the body for the email

.Body = sContent

.Send

End With



If bStarted Then

'If we started Outlook from code, then close it

oOutlookApp.Quit

End If



'Clean up

Set oItem = Nothing

Set oOutlookApp = Nothing





End Sub
 
J

Jean-Guy Marcil

Tim Cadieux was telling us:
Tim Cadieux nous racontait que :
I've got a Template to which I add a routing slip when the client
hits the Submit button. I also send a separate e-mail to one group
because their Service account will read the e-mail and add the job
directly into their work database. This Template works perfectly
fine on my Machine but on a number of other PCs, it simply shuts
down when it hits the first Route Recipient e-mail address¦

I've pasted the code belowI have a reference to Outlook 9.0 Object
Library

Is everyone using Outlook 2000?
Also, are you sure everyone has the same name for the recipients in their
address book? Or, do the recipients actually exists in each user's address
book?
From the VBA help:
"Note If the recipient name isn't in the global address book, an error
occurs."

By the way, there are spelling/grammatical mistakes:

MsgBox "The document has already been sent / Le document est envoyer."
MsgBox "Document sent/envoyer"

should be:

MsgBox "The document has already been sent / Le document a déjà été
envoyé."
MsgBox "Document sent/envoyé"

If you want to be fancy, you can detect the local language with
Application.Language
and then based on the result, present a message in the appropriate language,
as in:

Const myMessageFr As String = "Le document est envoyer."
Const myMessageEng As String = "The document has already been sent."

If Application.Language = msoLanguageIDFrench Then
MsgBox myMessageFr
Else
MsgBox myMessageEng
End If


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top