INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

E-mail Attached Files

VBA code E-Mail method (better than SendObject) by DougP
Posted: 10 Mar 01 (Edited 8 Apr 04)

This will send To, CC and BC as well as Subject, Message, and Attachment
You need 6 text boxes or variables which match the following:
txtMainAddresses
txtCC
txtBCC
txtSubject
txtBody
txtAttachment

Put this in your Module
------------------------------
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
------------------------------
put this in a command button
------------------------------
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

    Dim stext As String
    Dim sAddedtext As String
    If Len(txtMainAddresses) Then
        stext = txtMainAddresses
    End If
    If Len(txtCC) Then
        sAddedtext = sAddedtext & "&CC=" & txtCC
    End If
    If Len(txtBCC) Then
        sAddedtext = sAddedtext & "&BCC=" & txtBCC
    End If
    If Len(txtSubject) Then
        sAddedtext = sAddedtext & "&Subject=" & txtSubject
    End If
    If Len(txtBody) Then
        sAddedtext = sAddedtext & "&Body=" & txtBody
    End If
    If Len(txtAttachment) Then
        sAddedtext = sAddedtext & "Attach=" & Chr$(34) & txtAttachment & Chr$(34)
    End If
    
    stext = "mailto:" & stext
    
    If Len(sAddedtext) <> 0 Then
        Mid$(sAddedtext, 1, 1) = "?"
    End If
    
    stext = stext & sAddedtext
    
    ' launch default e-mail program
    If Len(stext) Then
        Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString, SW_SHOWNORMAL)
    End If
Exit_Command0_Click:
    Exit Sub

Err_Command0_Click:
    MsgBox Err.Description
    Resume Exit_Command0_Click
    
End Sub

------------------------------


Back to Microsoft: Access Modules (VBA Coding) FAQ Index
Back to Microsoft: Access Modules (VBA Coding) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close