Emailing from Access

drazen

Registered User.
Local time
Today, 05:06
Joined
Jan 28, 2016
Messages
31
Hi, i have 2 fairly simple Emailing issues.
I have a button, when I click the button I want it to email something to the email address on that record (the client), I want it to open outlook but not actually send it, as small adjustments may be made.
This is my code
Code:
Private Sub RFIEmail1_Click()
Dim strToWhom As String
Dim strMsgBody As String
Dim strSubject As String

strSubject = "Your appointment reminder"
strToWhom = Me.email 'clientsemailonthe form
strMsgBody = "this will be the message, usually a fixed message"

DoCmd.SendObject , , , strToWhom, , , strSubject, strMsgBody, True
End Sub

problem 1, In the 'To' line on outlook I get
name@client.co.uk#mailto:name@client.co.uk#
and it will not send.
How do i get it to just say name@client.co.uk ? without the 2nd name in hash tags.

Problem 2, If i kill of the outlook window without sending, i get an error :-
Runtime Error 2501
The sendObject action was canceled
Can I stop this error message?

thanks in advance
 
Your mail field seems to by a hyperlink to adjust for that use instr.
To avoid the error message us a error handler like:
Code:
Private Sub RFIEmail1_Click()
    Dim strToWhom As String
    Dim strMsgBody As String
    Dim strSubject As String
    
    On Error GoTo Error_RFIEmail1

    strSubject = "Your appointment reminder"
    strToWhom = Left(Me.email, InStr(Me.email, "#")) 'clientsemailonthe form (instr is required for a hyperlink field)
    strMsgBody = "this will be the message, usually a fixed message"

    DoCmd.SendObject , , , strToWhom, , , strSubject, strMsgBody, True

    Exit Sub
    
Error_RFIEmail1:
    If Err.Number = 2501 Then Exit Sub 'exit sub if send mail is canceled
    MsgBox "Error " & Err.Number & ", " & Err.Description 'Show error in other cases
        
End Sub
 
I don't use outlook, but did a few years back. You might give these a try:

1. Perhaps you are storing the "To" field as hypertext in your table??
You may have better luck using a string eg "therecipient@gmail.com"

2. Comment out the DoCmd.SendObject line.
You could do some debug.print statements to print to the immediate window those fields you want to see. Or you could create a string variable (for testing) that concatenates your various parts of the email and print that to immediate window, or to a text file or as a msgbox.


If you want to review/approve an email before sending, then you have to avoid the DoCmd.SendObject line.

Good luck
 
Thanks for the replies,
I've sorted them now, using instr worked a treat.

:)
 

Users who are viewing this thread

Back
Top Bottom