Populating an email body from Access

johntology

Registered User.
Local time
Today, 00:35
Joined
Apr 20, 2011
Messages
16
Hello,

I have a field in an Access form that I'm trying to put into the body of an email. It looks like there's a character limit of 752 characters for the body, regardless of the email client. Is there a better way of doing this:

Code:
Me.eSSS.SetFocus
Dim esssContent As String
esssContent = Me.eSSS.Text
Application.FollowHyperlink "mailto:?body=" & esssContent

I want to let the body text to not be limited by size and I want to be able to preserve and hard returns that were in the original field.

Thanks.
 
Lots in this. Firstly I would recommend you use the Outlook Object as the basis for your eMail code. Many posts here in the forum on that.

Then if you want a text box to be the basis for the body, I suggest you make the field a Memo. Then what I have used in the past is a bound PopUp form that shows the eMail body (or indeed a selection of them). Once selected, make this text a simple Report, which can then e output as a textfile - this text file is what you need to then become the body of your eMail as a text stream.

Here is some example code - not much of which I can claim credit for.!!

Code:
Option Compare Database
Option Explicit
' You need to declare a reference to the Outlook library, and the filesystemobject.
'
' Look in the menu above, and click Tools, then select References
'
' Scroll down the list until you see
' Microsoft Scripting Runtime -- and put a check next to it (if one is not there already)
'
' Microsoft Outlook Object Library -- check that.
'           There will be some version number there as well; it doesn't matter.
'           This will work with Outlook98 and Outlook2000


Public Sub SendeMailAttachment()

Dim db As DAO.Database
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
'

Dim FileAttachment As String
'

'Trap to handle No Send virus check
On Error GoTo NoSend
'
'
Dim Response As String
'
    'Write the e-mail body
    DoCmd.OpenForm "F-emailbodytext", , , , , acDialog
    '
    'Now output the file
    DoCmd.OutputTo acReport, "R-emailbodytext", "MS-DOSText(*.txt)", "c:\temp\emailbody.txt", False, "", 0
    '
'
Set fso = New FileSystemObject

' First, we need to know the subject.  We can't very well be sending around blank messages...

'We Need A Subject Line!")
Subjectline$ = "Your Quotation from Four Seasons"
'
'Default file name and path
BodyFile$ = "c:\temp\emailbody.txt"
'

If BodyFile$ = "" Then
    MsgBox "No body, no message." & vbNewLine & vbNewLine & "Quitting...", vbCritical, "I Ain't Got No-Body!"
    Exit Sub
End If

' Check to make sure the file exists...
If fso.FileExists(BodyFile$) = False Then
    MsgBox "The body file isn't where you say it is. " & vbNewLine & vbNewLine & "Quitting...", vbCritical, "I Ain't Got No-Body!"
    Exit Sub
End If

' Since we got a file, we can open it up.
    Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)

'and read it into a variable.
    MyBodyText = MyBody.ReadAll

' and close the file.
    MyBody.Close

' Now, we open Outlook for our own device..
    Set MyOutlook = New Outlook.Application

' Set up the database and query connections

    Set db = CurrentDb()
    '
        Set MyMail = MyOutlook.CreateItem(olMailItem)
            
    ' This addresses it
            
            MyMail.To = strQuotationeMail
            
            'This gives it a subject
            MyMail.Subject = Subjectline$
            
            'This gives it the body
            MyMail.Body = MyBodyText
    '
            FileAttachment$ = "c:\temp\Quotation_" & strClientNumber & ".pdf"
            '
            'Now check that the file exists - if the file has been output, it will be!!
            '
            If fso.FileExists(FileAttachment$) = False Then
            '
            MsgBox "The Attachment file is not where you say it is. " & vbNewLine & vbNewLine & _
            "Quitting...", vbCritical, "Incorrect file path"
            Exit Sub
            End If
            '
            MyMail.Attachments.Add FileAttachment$, olByValue, 1, "Quotation from Four Seasons"
            '
            'This sends it!
            MyMail.Send

'Cleanup after ourselves
Cleanup:

Set MyMail = Nothing

'Uncomment the next line if you want Outlook to shut down when its done.
'... otherwise, it will stay running.

'MyOutlook.Quit
Set MyOutlook = Nothing

db.Close
Set db = Nothing
'
Exit Sub
'Trap to handle No Send dialogue
NoSend:
'
If Err.Number = 287 Then
MsgBox "Send to Outbox Stopped", vbCritical, "Send Stopped"
GoTo Cleanup
'
Else
MsgBox "Send or Programme Error " & Err.Number & vbLf & Err.Description, vbCritical, "Send Stopped"
GoTo Cleanup
End If
'
End Sub
 
Thanks very much for that reply. If my customer uses Thunderbird as their email client, could any of this still apply?
 

Users who are viewing this thread

Back
Top Bottom