[AccessD] Using Outlook Redemption in Access

Bruce H. Johnson bhjohnson at verizon.net
Thu Jun 30 10:05:10 CDT 2005


Here's the code I use in VB. Note the Application is an Outlook Application:
Public Function EMail_SendMail() As Boolean
'Use late binding to avoid version refs?
'Requires only Recipient and Subject
Dim outApp As Object
Dim outNameSpace As Object
Dim redSafeItem As Object
Dim outItem As Object
Dim strItem As String
Dim lngNdx As Long
Dim outRec As Object

If SAFEOUTLOOK_RUNTIME Then On Error GoTo EMail_SendMail_Err
EMail_SendMail = False 'default
If strEMail_Recipient(0) = vbNullString Or strEMail_Subject = vbNullString
Then
   'Convert to messages when ready
   MsgBox "One recipient and subject required.", vbOKOnly Or vbExclamation,
"EMail_SendMail"
   EMail_SendMail = False
   GoTo EMail_SendMail_Exit
End If
Set outApp = CreateObject("Outlook.Application")
Set outNameSpace = outApp.GetNamespace("MAPI")
outNameSpace.Logon

Set redSafeItem = CreateObject("Redemption.SafeMailItem") 'Create an
instance of Redemption.SafeMailItem
Set outItem = outApp.CreateItem(0) 'Create a new Mail Item
redSafeItem.Item = outItem 'set Item property
'Add recipients
For lngNdx = 0 To UBound(strEMail_Recipient)
   strItem = Trim$(strEMail_Recipient(lngNdx))
   If Len(strItem) Then
      Set outRec = redSafeItem.Recipients.Add(strItem)
      outRec.Type = 1 'To
   Else
      Exit For
   End If
Next lngNdx
'redSafeItem.Recipients.ResolveAll
redSafeItem.Subject = strEMail_Subject
'Rest are optional
'CCs
For lngNdx = 0 To UBound(strEMail_CC)
   strItem = Trim$(strEMail_CC(lngNdx))
   If Len(strItem) Then
      Set outRec = redSafeItem.Recipients.Add(strItem)
      outRec.Type = 2 'CC
   Else
      Exit For
   End If
Next lngNdx
'redSafeItem.Recipients.ResolveAll
'BCC
For lngNdx = 0 To UBound(strEMail_BCC)
   strItem = Trim$(strEMail_BCC(lngNdx))
   If Len(strItem) Then
      Set outRec = redSafeItem.Recipients.Add(strItem)
      outRec.Type = 3 'BCC
   Else
      Exit For
   End If
Next lngNdx
redSafeItem.Recipients.ResolveAll
If Len(strEMail_Body) Then redSafeItem.Body = strEMail_Body
'Attachments
For lngNdx = 0 To UBound(strEMail_AttachmentFName)
   strItem = Trim$(strEMail_AttachmentFName(lngNdx))
   If Len(strItem) Then
      redSafeItem.Attachments.Add strItem, 1, CLng(Len(strEMail_Body) + 5)
'Embed by value, position
   Else
      Exit For
   End If
Next lngNdx
'If Len(strEMail_AttachmentFName) Then redSafeItem.Attachments.Add
strEMail_AttachmentFName
redSafeItem.Send 'puts in outbox or actually sends it
EMail_SendMail = True
Set outItem = Nothing
Set redSafeItem = Nothing
Set outNameSpace = Nothing
Set outApp = Nothing
GoTo EMail_SendMail_Exit

EMail_SendMail_Err:
MsgBox Err.Description, vbOKOnly Or vbExclamation, "EMail_SendMail"

EMail_SendMail_Exit:
'let objects fall out of reference
End Function 


Bruce H. Johnson
Sylmar, CA
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Christopher
Hawkins
Sent: Wednesday, June 29, 2005 4:40 PM
RE: REDEMPTION
Private Sub Blah()
Dim SafeItem, oItem  

    Set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an
instance of Redemption.SafeMailItem
    Set oItem = Application.CreateItem(0) 'Create a new message
    
    SafeItem.Item = oItem 'set Item property
    SafeItem.Recipients.Add "clh at christopherhawkins.com"
    SafeItem.Recipients.ResolveAll
    SafeItem.Subject = "Testing Redemption"
    SafeItem.Send
End Sub
[/CODE]

This code is triggered form a button click on a form.

When I run the code, I get an error message:

"Method or data member not found"

The error is on the .CreateItem method in the line that sets oItem to a new
item.






More information about the AccessD mailing list