K
Kenny G
Hello,
Just converted by Access 2003 DB into Access 2007. All the code worked up
until I tried to run the code for this module (see attached). I am now
getting the message "Type Mismatch". Is there something that has changed in
2007 that I don't know about.
I appreciate your assistance.
Option Compare Database
Option Explicit
Sub SendMessages(Optional AttachmentPath)
Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim ToAddress As String
Dim CCAddress As String
Dim sBody As String
'Dim BCCAddress As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblNonCompIPOPAllStandards")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipients to the e-mail message.
If Len(Forms!frmMail!txtToAddress & vbNullString) > 0 Then
Set objOutlookRecip = .Recipients.Add(Forms!frmMail!txtToAddress)
objOutlookRecip.Type = olTo
End If
' Add the Cc recipients to the e-mail message.
If Len(Forms!frmMail!txtCCAddress & vbNullString) > 0 Then
Set objOutlookRecip = .Recipients.Add(Forms!frmMail!txtCCAddress)
objOutlookRecip.Type = olCC
End If
' Add the BCC recipients to the e-mail message.
'If Len(Forms!frmMail!txtBCCAddress & vbNullString) > 0 Then
'Set objOutlookRecip = .Recipients.Add(Forms!frmMail!txtBCCAddress)
'objOutlookRecip.Type = olBCC
'End If
sBody = "Attached are the results of the tracer survey performed on
your unit.<br>"
sBody = sBody & "Please review report and note the identified
areas requiring improvement.<br><br>"
sBody = sBody & "Necessary corrective actions for identified
deficiencies should be implemented<br>"
sBody = sBody & "in your area. We will be doing a follow up
survey to evaluate changes.<br><br>"
sBody = sBody & "Please feel free to contact me or Kimberly
Gonzalez should you have any questions<br>"
sBody = sBody & "or need assistance with patient safety or Joint
Commission issues.<br><br>"
sBody = sBody & "Thank you.<br><br><br>"
sBody = sBody & "PV/KG<br>"
' Set the Subject, the Body, and the Importance of the e-mail message.
.Subject = "Tracer Survey Report!"
.Importance = olImportanceHigh 'High importance
.HTMLBody = sBody
'Add the attachment to the e-mail message.
Set objOutlookAttach = .Attachments.Add("S:\Quality & Process
Improvement\QPI\JCAHO PreSurvey Tool\Documents\CurrentPreSurveyReport.snp")
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Display
'.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
Just converted by Access 2003 DB into Access 2007. All the code worked up
until I tried to run the code for this module (see attached). I am now
getting the message "Type Mismatch". Is there something that has changed in
2007 that I don't know about.
I appreciate your assistance.
Option Compare Database
Option Explicit
Sub SendMessages(Optional AttachmentPath)
Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim ToAddress As String
Dim CCAddress As String
Dim sBody As String
'Dim BCCAddress As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblNonCompIPOPAllStandards")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipients to the e-mail message.
If Len(Forms!frmMail!txtToAddress & vbNullString) > 0 Then
Set objOutlookRecip = .Recipients.Add(Forms!frmMail!txtToAddress)
objOutlookRecip.Type = olTo
End If
' Add the Cc recipients to the e-mail message.
If Len(Forms!frmMail!txtCCAddress & vbNullString) > 0 Then
Set objOutlookRecip = .Recipients.Add(Forms!frmMail!txtCCAddress)
objOutlookRecip.Type = olCC
End If
' Add the BCC recipients to the e-mail message.
'If Len(Forms!frmMail!txtBCCAddress & vbNullString) > 0 Then
'Set objOutlookRecip = .Recipients.Add(Forms!frmMail!txtBCCAddress)
'objOutlookRecip.Type = olBCC
'End If
sBody = "Attached are the results of the tracer survey performed on
your unit.<br>"
sBody = sBody & "Please review report and note the identified
areas requiring improvement.<br><br>"
sBody = sBody & "Necessary corrective actions for identified
deficiencies should be implemented<br>"
sBody = sBody & "in your area. We will be doing a follow up
survey to evaluate changes.<br><br>"
sBody = sBody & "Please feel free to contact me or Kimberly
Gonzalez should you have any questions<br>"
sBody = sBody & "or need assistance with patient safety or Joint
Commission issues.<br><br>"
sBody = sBody & "Thank you.<br><br><br>"
sBody = sBody & "PV/KG<br>"
' Set the Subject, the Body, and the Importance of the e-mail message.
.Subject = "Tracer Survey Report!"
.Importance = olImportanceHigh 'High importance
.HTMLBody = sBody
'Add the attachment to the e-mail message.
Set objOutlookAttach = .Attachments.Add("S:\Quality & Process
Improvement\QPI\JCAHO PreSurvey Tool\Documents\CurrentPreSurveyReport.snp")
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Display
'.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub