I need to send an encrytped email from a form using outlook. I found some code on the net, but am getting an error of "Method or Data Member not found" on encryptButton.Execute. I am not having much luck in finding any documentation or information and would appreciate any ideas or suggestions.


Private Sub cmdSendEmail_Click()
Dim objOutlook As Outlook.Application
Dim objMailItem As Outlook.MailItem
Set objOutlook = New Outlook.Application
Set objMailItem = objOutlook.CreateItem(olMailItem)

Dim outlookCommandBars As Outlook.OutlookBarGroups
Dim encryptButton As CommandButton
Dim signButton As CommandButton




With objMailItem
.To = "test@mail.com"

.CC = "test@mail.com"

.Subject = "Test Email Encrypt"
.Body = "Is this email encryted?"
' .Attachments.Add (strOfrLtrName) ' attach any files here
.Save

.Display


Set outlookCommandBars = .GetInspector.CommandBars

Set encryptButton = outlookCommandBars.FindControl(msoControlButton, 718)

If encryptButton Is Nothing Then
Set encryptButton = outlookCommandBars.Item("Standard").Controls.Add(m soControlButton, 718, , , False)
End If

Set signButton = outlookCommandBars.FindControl(msoControlButton, 719)

If signButton Is Nothing Then
Set signButton = outlookCommandBars.Item("Standard").Controls.Add(m soControlButton, 719, , , False)
End If

encryptButton.Enabled = True
signButton.Enabled = True

If encryptButton.Enabled = True Then
If (eSecurity = msEncrypted Or eSecurity = msSignedAndEncrypted) Then
encryptButton.Execute
End If
Else
MsgBox "You do not have an Encryption Certificate! " & _
"This message will not be sent. You must have an encryption certificate to be able to send secure messages!", vbCritical
.Close olDiscard
End If
If signButton.Enabled = True Then
If (eSecurity = msSigned Or eSecurity = msSignedAndEncrypted) Then
signButton.Execute
End If
MsgBox "You do not have a Signing Certificate! " & _
"This message will not be sent. You must have an encryption certificate to be able to send secure messages!", vbCritical
.Close olDiscard
End If
End With
End Sub