I have an MS-Access VBA routine that calls vbSendMail, using a CLASS module.
vbSendMail documentation (at www.freevbcode.com/ShowCode.Asp?ID=109
) says that the DLL will raise the SendSuccessful event if successful, else the SendFailed event after sending the mail. I presume that I do not instantiate these in my main module.
Firstly, these events in my Class module are not called; secondly I am not clear how I pass the obtained result back to my main module and how to make the main module wait until the relevant event has fired.
In calling the Property Get for the return status, I get a compile error "Argument not optional" - why? how should I code this?
In the Class module events, I have a temporary Msgbox statement to confirm that the event is indeed not being called, lest the problem was just in passing the status back to the main module.
This follows on from www.experts-exchange
Sorry experts, but I closed that one a bit too soon. Anyhow, here is your chance to earn some more points. (Am I being a bit mean - is this issue worth much more?)
Private gstrReturnStatus As String
Public Sub SendSuccesful()
MsgBox "Email sent successfully"
gstrReturnStatus = "OK"
Public Sub SendFailed(P_Explanation As String)
MsgBox "Email send failed: " & vbCrLf & P_Explanation
gstrReturnStatus = P_Explanation
Public Property Get ReturnStatus(ByVal Value As String)
Value = gstrReturnStatus
' Main module
Dim MailStatus As String
Dim I, OpenForms
On Error GoTo Err_mySendOneEMail
' Initialize the MailAgent:
Dim objMail As New Class2MailAgent
MailStatus = ""
objMail.Sender_id = P_user_id
objMail.Recipient_id = P_Recipient_id
objMail.Subject = P_subject
objMail.Message = P_message
objMail.Attachment = P_Attachment
' Wait until we get a return status:
' See http://office.microsoft.com/en-us/access/HA012288271033.aspx
For I = 1 To 150000
If I Mod 1000 = 0 Then
OpenForms = DoEvents ' surrender resources to other processes
MailStatus = objMail.ReturnStatus() ' Compile error
MsgBox "Status was " & MailStatus
If MailStatus <> "" Then
MsgBox "Email status = " & MailStatus