Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009

    Unanswered: send email using smtp

    Hi There.

    How do I send an email from MSaccess 2003 using VBA?

    does anyone have any code that I could use to do this?

    Thanks in advance.


  2. #2
    Join Date
    Nov 2008

    Send email

    Hi I use the following code which may be of assistance.

    the calling function is:
    Call SendMsg(True, strTo, strSubject, strbody, strCC, strBCC, strAttachment, "Send Accident Report")

    The modules has
    Public Function SendMsg(ishtml As Boolean, strTo As String, strSubject As String, strbody As String, _
    Optional strCC As String = "", _
    Optional strBCC As String = "", _
    Optional strAttachment As String = "", _
    Optional strReason As String = "") As Boolean
    On Error GoTo err_trap

    'strTo: list of primary recipients' E-mailAddresses, semi-colon delimited
    'strCC: list of CC recipient's E-mailAddresses, semi-colon delimited
    'strBCC: list of BCC recipient's E-mailAddresses, semi-colon delimited
    'strAttachment list of attachments, semi-colon delimited
    If strTo = "" Or Len(strTo) < 1 Then Exit Function 'exit if not valid of course
    If strSubject = "" Or Len(strSubject) < 1 Then Exit Function 'exit if not valid of course
    If strbody = "" Or Len(strbody) < 1 Then Exit Function 'exit if not valid of course
    Dim extracomment As String
    'now to add extra bit in to aske for additional comments to be included in the email
    extracomment = InputBox("Type in anything extra you wish sent with this email in the body of the message!" & vbCrLf & "This will not be saved!", "Extra Information", "")
    If Not IsNothing(extracomment) Or Not IsNull(extracomment) Then strbody = extracomment & vbCrLf & vbCrLf & strbody

    Dim strArray() As String, intCount As Integer
    Dim OlApp As Outlook.Application
    Dim oItem As Outlook.MailItem
    Set OlApp = CreateObject("Outlook.Application")
    Set oItem = OlApp.CreateItem(0)
    On Error Resume Next
    DoCmd.SetWarnings False

    With oItem
    ' .Importance = olImportanceHigh 'High importance
    .Subject = strSubject
    .To = strTo
    If ishtml = True Then
    .HTMLBody = strbody
    .body = strbody
    End If
    If Not IsNothing(strCC) Then .cc = strCC
    If Not IsNothing(strBCC) Then .BCC = strBCC
    If Not IsNothing(strAttachment) Then .attachments.Add Trim(strAttachment)
    'strattachment may be x; y; z so have to split them and then add individually
    If Not IsNothing(strAttachment) Then
    strArray = Split(strAttachment, ";")
    For intCount = LBound(strArray) To UBound(strArray)
    .attachments.Add Trim(strArray(intCount))
    End If

    End With
    DoCmd.SetWarnings True

    Set oItem = Nothing
    Set OlApp = Nothing
    SendMsg = True

    'you can add any error trapping in here if you wish
    Set oItem = Nothing
    Set OlApp = Nothing
    SendMsg = False
    Exit Function

    End Function

  3. #3
    Join Date
    Nov 2007
    Adelaide, South Australia
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!

    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts