Sending email from VB (1 Viewer)

widemonk

Registered User.
Local time
Today, 02:01
Joined
Jun 16, 2005
Messages
48
Im trying to send an email from VB...

Code:
Private Sub lblEmail_Click()
DoCmd.SendObject acSendNoObject, , acFormatRTF, txtEmail, , , "YourSubject", _
"YourMessage", True
End Sub

I have tried both acFormatTXT and acFormatRTF. I've also tried a few others too but didnt expect them to work anyway, for instance acFormatXLS.

Every time, I get the error message 'Microsoft Access cant open the mail session.'

It is not because the txtEmail field is blank, because other code makes sure the email button is only visible if an email address is present.

Running Access 2000, Vista :)eek:) and Windows Mail

Thanks
 

dkinley

Access Hack by Choice
Local time
Yesterday, 20:01
Joined
Jul 29, 2008
Messages
2,016
Here is a link where I discuss how to send a report in e-mail ...

http://www.access-programmers.co.uk/forums/showthread.php?t=155673&highlight=send+email

But since you are not sending an attachment the .rtf or .txt is not an issue, so you can just use something like the following ...

Well, before I post that it seems you have something called a 'label' trying to do this - it should be a command button.

So suppose, you have a command button, and you name it 'cmdSendEmail'. Also, suppose you have a control on the form that held the e-mail address and it was named 'txtEmail' (if not, you can delete that part and type in your own - see the thread link for a static e-mail or ignore all of it to type it in on the email itself) then the code on the click event will look like ...

Code:
Private Sub cmdSendEmail_Click()
On Error GoTo Err_cmdSendEmail_Click
    Dim sToName As String
    Dim sSubject As String
 
    If Len(Nz(Me.txtEmail, "")) = 0 Then
        MsgBox "There is no e-mail address to send to.", , "No E-mail Address"
        Me.txtEmail.SetFocus
    Else
        sSubject = InputBox("Input the subject line.", "Subject Line", "")
        sToName = [txtEmail]
    
        DoCmd.SendObject , , , _
        sToName, , , _
        sSubject, , True, False
    End If
 
Exit_cmdSendEmail_Click:
    Exit Sub
Err_cmdSendEmail_Click:
    MsgBox "The request to send an e-mail has been cancelled.", , "Cancel E-mail"
    Resume Exit_cmdSendEmail_Click
End Sub

I didn't list the error number specifically, but a general catch-all if there is any error.

-dK
 

Users who are viewing this thread

Top Bottom