SendObject canceled

Eikenhorst

Registered User.
Local time
Today, 16:45
Joined
Mar 9, 2007
Messages
25
Hello,

I’m working on an unbound form that has sends the information on the form by mail to a user after the information has been saved to the table and before the new information is loaded.
The users have to send this e-mail, even though most of them don’t want to. But Windows now gives a warning if a program tries to send an e-mail and they can choose not to send it. This will result in an error message “Microsoft Office Access can’t send this e-mail message”.

I don’t want the users to be able to reject sending that e-mail. But I understand that this will not be possible under Windows. So I want to catch them in an on error statement saying that they have to send this e-mail, and then try to mail it again.

This code will have to look like this:

On Error GoTo Message
Retry:
DoCmd.SendObject acSendForm, “Testform”, acFormatXLS, “User”, , , , ,False
Goto Continue
Message:
MsgBox “You have to send this e-mail in order to continue”
GoTo Retry
Continue:

For some reason the On Error code doesn’t prevent this error message from showing. What am I doing wrong here? Any help is greatly appreciated!
 
You can also use CDO, or Collaboration Data Objects--I think--to send mail entirely independent of any email client. Most parameters are self-explanatory, but the smtpServer is not actually optional. It is the same servername your email client uses to send mail, and looks something like 'mail.yourisp.com'. If you run this your user doesn't even have to know that mail was sent.

Code:
Public Sub Send(recipients As String, from As String, subject As String, Optional msg As String, Optional attachPath As String, Optional smtpServer As String)
On Error GoTo handler
   Dim iMsg As New CDO.Message
   Dim iConf As New CDO.Configuration
   
   'set up configuration
   With iConf
      With .fields
         .item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
         .item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
         .item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
         .item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
         .Update
      End With
   End With
   
   'configure message
   With iMsg
       Set .Configuration = iConf
       .To = recipients
       .from = from
       .subject = subject
       If msg <> "" Then .TextBody = msg
       If attachPath <> "" Then .AddAttachment attachPath
       .Send
   End With
   
   'tidy up
   Set iMsg = Nothing
   Set iConf = Nothing
   Exit Sub

handler:
   Err.Raise Err, Err.Source & " - Lib.CDOMail.Send()"
End Sub
 

Users who are viewing this thread

Back
Top Bottom