Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

send auto-mail with file attachment from local drive

Posted on 2001-09-03
6
Medium Priority
?
344 Views
Last Modified: 2010-08-05
My Problem:
I have to take a file from Disk (Drive C:\) and take this file as an attachment to an mail and send it automatical.


0
Comment
Question by:Schobert
  • 4
6 Comments
 
LVL 12

Accepted Solution

by:
Paurths earned 900 total points
ID: 6450413
hi Schobert,

u can use the open/save dialog to pick the file, u'll find an example here : http://www.mvps.org/access/api/api0001.htm


and here is the code for sending email with attachment: (in this example the retrieved file is strFileSelected)

Private Sub cmdSending_Click()
Dim rs As DAO.Recordset
Dim strMsg As String
Dim strSub As String

    strMsg = "Type the email body..."
    strSub = "Type the subject for the message here..."

    SendMessage "person@where.com", strMsg, strSub, strFileSelected
           
End Sub


Private Sub SendMessage(strTo As String, strMsg As String, strSub As String, Optional AttachmentPath)
  Dim objOutlook As Outlook.Application
  Dim objOutlookMsg As Outlook.MailItem
  Dim objOutlookRecip As Outlook.Recipient
  Dim objOutlookAttach As Outlook.Attachment

  ' Create the Outlook session.
  Set objOutlook = CreateObject("Outlook.Application")

  ' Create the message.
  Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

  With objOutlookMsg
     ' Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add(strTo)
     objOutlookRecip.Type = olTo

     ' Set the Subject, Body, and Importance of the message.
     .Subject = strSub
     .Body = strMsg & vbCrLf & vbCrLf
     .Importance = olImportanceHigh  'High importance

     ' Add attachments to the message.
     If Not IsMissing(AttachmentPath) Then
        Set objOutlookAttach = .Attachments.Add(AttachmentPath)
     End If

     ' Resolve each Recipient's name.
     For Each objOutlookRecip In .Recipients
        objOutlookRecip.Resolve
        If Not objOutlookRecip.Resolve Then
        objOutlookMsg.Display
     End If
     Next
     .Send

  End With
  Set objOutlookMsg = Nothing
  Set objOutlook = Nothing

End Sub


hope this  helps,
Ricky
0
 
LVL 12

Expert Comment

by:Paurths
ID: 6450426
btw, u should adjust the open/save function so that it will return the path and name of the selected file:


Private Sub cmdSending_Click()
Dim strMsg As String
Dim strSub As String
dim strFileSelected as variant

   strFileSelected = TestIt()
   strMsg = "Type the email body..."
   strSub = "Type the subject for the message here..."

   SendMessage "person@where.com", strMsg, strSub, strFileSelected
           
End Sub





Function TestIt() as variant
    Dim strFilter As String
    Dim lngFlags As Long
    strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
                    "*.MDA;*.MDB")
    strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
    strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
    strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
    MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
        Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
        DialogTitle:="Hello! Open Me!")
    ' Since you passed in a variable for lngFlags,
    ' the function places the output flags value in the variable.
    Debug.Print Hex(lngFlags)
End Function
0
 
LVL 12

Expert Comment

by:Paurths
ID: 6450434
u can also adjust the filter set in the dialog (and an adjustment to the returning value that i forgot...)
only choosing excel files:

Function TestIt() As Variant
    Dim strFilter As String
    Dim lngFlags As Long
    strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", _
                    "*.xls")
    TestIt = ahtCommonFileOpenSave(InitialDir:=strLoc, _
        Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
        DialogTitle:="Hello! Open Me!")

End Function
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 2

Expert Comment

by:JamesMayfield
ID: 6451771
What email program are you using? Does it have to serve various mail programs?

This is actually a fairly simple one. Answer the above two questions and I'll give you some code that does it.
0
 

Author Comment

by:Schobert
ID: 6452253
Hi,
It was possilbe to solve the problem as I have seen Your proposal, but the code worked not emediately on my computer ( I thinke it depends not on Your code).
Thanke You for Your quick help !
best regards,
Sigi Schobert
0
 
LVL 12

Expert Comment

by:Paurths
ID: 6452514
hi Schobert,

glad it helped u with sending those emails,
i am wondering a little why this code is only worth a B-grade.
It is excellent code i provided.
Please dont feel like this is attacking you in anyway, it is not.
I am just curious.

cheers
Ricky
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question