Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emailing in Access

Status
Not open for further replies.

Dons1000

Programmer
Jul 18, 2006
17
0
0
US
Hello, I have a Access 2003 app that uses SQL Server 2005 as the backend. I need to create a form in Access that the user enters the email address, the subject, body and any attachments to be included in the email. This would get saved into a sql server table, then an email would get generated includeing the attachment that the From is the user who entered the data in the form.

How do people usually do email features like this in Access?

Thanks
 
here's a routine i wrote that enables you to supply a HTML text string, any attachments , recipient etc..

Code:
Sub SendEmail(ByVal sTo As String, ByVal sSubject As String, ByVal sbody As String, Optional sFile As String, Optional sBlind As String)

    On Error GoTo EH_SendEmail
    
    Dim oApp As Outlook.Application
    Dim sEmail As String
    Dim iPos As Integer
    Dim i As Integer
    Dim iCount As Integer
    Dim oMailItem As Outlook.MailItem
    Dim oReceipt As Outlook.Recipient
    Dim oAttach As Outlook.Attachment '- use to attach a file
    
    'open Outlook
    Set oApp = CreateObject("Outlook.Application")
       
    'Create mail message
    Set oMailItem = oApp.CreateItem(olMailItem)
    
    With oMailItem
        Set oReceipt = .Recipients.Add(sTo)
        oReceipt.Type = olTo
        .Subject = sSubject
        ' .Body = sBody ' changed to be HTML email
        .HTMLBody = sbody
        'if Blind Copy needed
        If Not IsNull(sBlind) And sBlind <> "" Then
            .BCC = sBlind
        End If
         'use to attach a file at sFile
        If Not IsNull(sFile) And sFile <> "" Then
            Set oAttach = .Attachments.Add(sFile)
        End If
        'send to outlook outbox
        .Send
    End With
        
    Set oReceipt = Nothing
    Set oAttach = Nothing
    Set oMailItem = Nothing
        
    Set oApp = Nothing

    Exit Sub
EH_SendEmail:
    MsgBox "Error in EH_SendEmail " & Error(Err) & " " & CStr(Err)
    Resume Next
End Sub

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top