davidboutche
08-05-2009, 05:27 AM
I have the following code as part of a larger file that should run the email procedure that would select certain book marks and compose and email ready to be send as part of an IF Statement.
The Else Statement should run another email procedure.
However, when it comes to executing the email procedure if gives the following error message:
"Microsoft Office Wordmail could not be started. Close any open dialogue boxes and try again."
Private Sub UserForm_Initialize()
violencecombo_box.AddItem "YES"
violencecombo_box.AddItem "NO"
supervisorRankComboBox.AddItem "Acting Sergeant"
supervisorRankComboBox.AddItem "Sergeant"
supervisorRankComboBox.AddItem "Acting Inspector"
supervisorRankComboBox.AddItem "Inspector"
End Sub
Private Sub ChecklistnextButton_Click()
If violencecombo_box.Value = "YES" Then
MsgBox ("There are no PNDs that are suitable for issue when violence has been used. If you try to proceed with this PND, the ticket WILL be cancelled.The offender WILL be given their money back.Instead, make contact with CJD immediately and ask for help with a suitable disposal.")
Call eMailActiveDocument
'ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Application.Quit
Else: Call eMailCIBNonCourt
End If
Call FillBM("supervisorrankbook", genericcheckform.supervisorRankComboBox.Text)
Call FillBM("supervisornamebook", genericcheckform.supervisornamebox.Text)
Unload Me
End Sub
Also I can't work out how to split the long msgbox using the _.
When I comment out the email procedures it works fine each time.
The email procedures are as below using late binding (i think).
Option Explicit
Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
With EmailItem
.Subject = "Alternate disposal for PND required"
.Body = "PND " & UserForm1.PNDbox.Text & " has been incorrectly issued. It has been identified that the offence for which the PND was issued does not fit within the scope of the scheme. The PND was issued on " & UserForm1.issuedatebox.Text & "." & vbCrLf & _
"Please make contact with me to discuss alternative disposals for this offence." _
& vbCrLf & "Regards" & vbCrLf _
& UserForm1.officerbox.Text
.To = "Insert your local case director email"
.Importance = 1 ' olImportanceHigh 'Or olImprotanceHigh Or olImprotanceLow
' .Attachments.Add Doc.FullName
' .Send
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
Sub eMailCIBNonCourt()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
' Doc.Save
With EmailItem
.Subject = "A PND has been issued"
.Body = "A Penalty Notice for Disorder has been issued out of custody. The PND is number " & _
UserForm1.PNDbox.Text & "for" & UserForm1.offenceCombo_Box.Text & "Issued by: " & UserForm1.officerbox.Text
.To = ".Non Court Disposals; .Central Input Bureau"
.Importance = 2
' .Attachments.Add Doc.FullName
' .Send
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
Any help, really appreciated. I've been looking at this for days and can't work out why.
:think:
The Else Statement should run another email procedure.
However, when it comes to executing the email procedure if gives the following error message:
"Microsoft Office Wordmail could not be started. Close any open dialogue boxes and try again."
Private Sub UserForm_Initialize()
violencecombo_box.AddItem "YES"
violencecombo_box.AddItem "NO"
supervisorRankComboBox.AddItem "Acting Sergeant"
supervisorRankComboBox.AddItem "Sergeant"
supervisorRankComboBox.AddItem "Acting Inspector"
supervisorRankComboBox.AddItem "Inspector"
End Sub
Private Sub ChecklistnextButton_Click()
If violencecombo_box.Value = "YES" Then
MsgBox ("There are no PNDs that are suitable for issue when violence has been used. If you try to proceed with this PND, the ticket WILL be cancelled.The offender WILL be given their money back.Instead, make contact with CJD immediately and ask for help with a suitable disposal.")
Call eMailActiveDocument
'ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Application.Quit
Else: Call eMailCIBNonCourt
End If
Call FillBM("supervisorrankbook", genericcheckform.supervisorRankComboBox.Text)
Call FillBM("supervisornamebook", genericcheckform.supervisornamebox.Text)
Unload Me
End Sub
Also I can't work out how to split the long msgbox using the _.
When I comment out the email procedures it works fine each time.
The email procedures are as below using late binding (i think).
Option Explicit
Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
With EmailItem
.Subject = "Alternate disposal for PND required"
.Body = "PND " & UserForm1.PNDbox.Text & " has been incorrectly issued. It has been identified that the offence for which the PND was issued does not fit within the scope of the scheme. The PND was issued on " & UserForm1.issuedatebox.Text & "." & vbCrLf & _
"Please make contact with me to discuss alternative disposals for this offence." _
& vbCrLf & "Regards" & vbCrLf _
& UserForm1.officerbox.Text
.To = "Insert your local case director email"
.Importance = 1 ' olImportanceHigh 'Or olImprotanceHigh Or olImprotanceLow
' .Attachments.Add Doc.FullName
' .Send
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
Sub eMailCIBNonCourt()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
' Doc.Save
With EmailItem
.Subject = "A PND has been issued"
.Body = "A Penalty Notice for Disorder has been issued out of custody. The PND is number " & _
UserForm1.PNDbox.Text & "for" & UserForm1.offenceCombo_Box.Text & "Issued by: " & UserForm1.officerbox.Text
.To = ".Non Court Disposals; .Central Input Bureau"
.Importance = 2
' .Attachments.Add Doc.FullName
' .Send
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
Any help, really appreciated. I've been looking at this for days and can't work out why.
:think: