Solved

EMail a file out of an Access Application

Posted on 1998-10-30
22
248 Views
Last Modified: 2008-02-20
Hello!

I've posted this question some days ago, but no really satisfactory answer reached me. browdog nearly answerd my question, but not entirely.

Here is my problem:

I simply want to send a file (e.g. teris.exe) out of my access application. I need a code (or something else), where I can specify:

1. The deliverer
2. The topic
3. The file(s) and maybe some additional text
 Just as in any ordinary Mail.

So, I offer 100 Points for a complete answer. (I use Access 97)

Thanks in advance
0
Comment
Question by:casexpert
  • 11
  • 6
  • 3
  • +1
22 Comments
 

Author Comment

by:casexpert
ID: 1967255
Edited text of question
0
 
LVL 1

Expert Comment

by:susannahbond
ID: 1967256
If the file you want to send is in the format .xls .rtf .txt
why don't you use SendObject, this will open mail add a file and add further text etc.

This is a sample of one I have used.....
 DoCmd SendObject A_REPORT, "AntennaStatusXLStagOrder", A_FORMATXLS, , , , "Analysis Request No. " & forms![site]![analysissub].form![ID] & ", data", "Please find attached a spreadsheet with the relevant antenna information for " & [SITeNAME] & ", site No. " & [Code]

I guess I may be missing the point, teris.exe is a program, do you want to send data or an external file?
0
 

Author Comment

by:casexpert
ID: 1967257
Oh, susannahbond

If you would have read the question, you would have recognized, that my example is the file Tetris.exe. And as far as I'm informed, this is not a Access Report or Form or Table or something else. I know the SendObject Function, but this is not what I'm searching for
0
 
LVL 1

Expert Comment

by:susannahbond
ID: 1967258
"Don't you cry for me"
0
 
LVL 2

Expert Comment

by:joslad
ID: 1967259
I did something like this recently.  Are you using Outlook98?

joslad
0
 
LVL 2

Expert Comment

by:joslad
ID: 1967260
Couple of other things I should have asked too.

Is the email address of the destination recipient stored in a field in the database.  Also, is the topic stored in a field.
0
 

Author Comment

by:casexpert
ID: 1967261
No, joslad

Just Microsoft Exchange
0
 

Author Comment

by:casexpert
ID: 1967262
To joslad:

If it is important to store the informations in data fields, it would be no problem
0
 

Author Comment

by:casexpert
ID: 1967263
Adjusted points to 150
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1967264
Have you looked at MSDN Q153311 ?

I had a go with an attachment and the best I have got so far is that it waits in exchange in the outbox, but doesn't do the final delivery.

It also cocked up a dll and froze the computer several times (though not when I sent a message without an attachment)

Anyway it's worth having a look at, you might be able to work something out from it.
0
 
LVL 2

Expert Comment

by:joslad
ID: 1967265
The solution I had which does what you wanted, actually uses outlook98.  So, sorry cant help.


0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 8

Expert Comment

by:Helicopter
ID: 1967266
casexpert:this is the solution Microsoft offers. It is almost identical to the MSDN article I referred to. Remember to change the names of recipients and your profile name.




Using Automation to Send a Microsoft MAPI Message

There are five main steps in sending a MAPI message through Automation:


·      Initializing and logging onto the MAPI session
·      Creating a new message and adding it to the Outbox
·      Adding the recipients (To, CC, and BCC) and resolve names
·      Setting valid properties, such as text, subject, and importance
·      Sending the message



   '-------------------------------------------------------------------
   ' This procedure sets an object variable to the MAPI Session object
   ' using the CreateObject() function. Then, it logs on to the session
   ' using a predefined profile. Once logged on, the procedure creates
   ' a new message and adds it to the Messages collection of the user's
   ' OutBox. Then, it creates two recipients (one on the TO: line and
   ' one on the CC: line) and adds both to the Recipients collection

   ' of the message. Next, it resolves the names of all recipients.
   ' Then, it attaches a sample file before filling in the Subject,
   ' Text, and Importance attributes of the message.
   '-------------------------------------------------------------------
    Sub SendMAPIMessage()
        Dim MapiSession As Object
        Dim MapiMessage As Object
        Dim MapiRecipient As Object
        Dim MapiAttachment As Object

        Dim Recpt
        Dim errObj As Long
        Dim errMsg

        On Error GoTo MAPITrap
        ' Create the MAPI Session.
        Set MapiSession = CreateObject("Mapi.Session")

        ' Log on to the session. If the ProfileName argument is
        ' omitted, Microsoft Exchange prompts you for the profile to
        ' use. If the profile name is incorrect, you will receive a
        ' runtime error.


         MapiSession.Logon profilename:="Steven Buchanan"

        ' Add a message to the Outbox.
        Set MapiMessage = MapiSession.Outbox.Messages.Add

        ' Add the recipients of the message. Note, each recipient must
        ' be added separately to the Recipients collection of the
        ' Message object.

        With MapiMessage
            Set MapiRecipient = MapiMessage.Recipients.Add
            MapiRecipient.Name = "Nancy Davolio"

            MapiRecipient.Type = mapiTo
            Set MapiRecipient = MapiMessage.Recipients.Add
            MapiRecipient.Name = "Andrew Fuller"
            MapiRecipient.Type = mapiCc
            Set MapiRecipient = MapiMessage.Recipients.Add
            MapiRecipient.Name = "Michael Suyama"
            MapiRecipient.Type = mapiBcc

            ' Resolve each recipient's e-mail name.
            For Recpt = 0 To .Recipients.Count - 1

                .Recipients(Recpt).Resolve showdialog:=False
            Next

            ' Attach a file to the message.
            Set MapiAttachment = MapiMessage.Attachments.Add
            With MapiAttachment
                .Name = "Customers.txt"
                .Type = mapiFileData
                .Source = "C:\Examples\Customers.txt"
                .ReadFromFile filename:="C:\Examples\Customers.txt"
                .position = 2880

            End With

            ' Assign the text, subject, and importance of the message.
            .subject = "My Subject"
            .Text = "This is the text of my message." & vbCrLf & vbCrLf
            .importance = mapiHigh

            ' View the message in Microsoft Exchange before sending.
            ' Set the ShowDialog argument to False if you want to send
            ' the message without viewing it in Microsoft Exchange.


            .Send showdialog:=True
        End With
        Set MapiSession = Nothing  ' Clear the object variable.

    MAPIExit:
        Exit Sub

    MAPITrap:
        ' Strip out the OLE automation error.
        errObj = Err - vbObjectError

        Select Case errObj
            Case 275       ' User cancelled sending of message.
                Resume MAPIExit
            Case Else

                errMsg = MsgBox("Error " & errObj & " was returned.")
                Resume MAPIExit
            End Select
    End Sub



0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1967267
Me again. This bit is useful too:

Microsoft OLE Messaging

The Microsoft OLE Messaging server works with MAPI. It allows you to send, receive and process electronic mail, including faxes. This server does not support early binding so you must use late binding.  MAPI can become challenging because you may find two mail servers available on your PC: the “Mapi.Session” server described herein and the “MSMAPI.MAPISession” that is part of  MSMAPI.OCX. You can call CreateObject successfully with “MSMAPI.MAPISession” but this instance is very different from a OLE Messaging instance.

For Office 97 users, you should consider automating Microsoft Outlook  for your electronic messaging needs.  The object model is much simpler and documented much better than the OLE Messaging 1.0 library.

NOTE: The following examples require the Microsoft OLE Messaging 1.0 Object Library(mdisp32.tlb) in order to work. It is not provided with the Microsoft Exchange component which ships with Windows 95. You must purchase Microsoft Exchange separately to obtain this object library.

(mdisp32.tlb should be in your system folder, you need to make a reference to it from access)
0
 

Author Comment

by:casexpert
ID: 1967268
Thank you for your answer, helicopter,

but as I tryed the code the following Error occured:

Error 196695 was returned

The Error occurs here:

        ' Attach a file to the message.
         Set MapiAttachment = MapiMessage.Attachments.Add
         With MapiAttachment
             .Name = "Langbrit.xls"
             .Type = mapiFileData                      ******  ERROR IN THIS LINE ************
             .Source = "C:\Temp\Langbrit.xls"
             .ReadFromFile filename:="C:\Temp\Langbrit.xls"
             .position = 2880
           
         End With

0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1967269
These values range from 1 to 4 (look up mapiattachmenttype in the object browser) Is your error because you haven't made a reference to the OLEmessaging library.

If not, try the other values.
0
 

Author Comment

by:casexpert
ID: 1967270
Post the answer again. It is great. It works!!! I love it. Yes.




0
 

Author Comment

by:casexpert
ID: 1967271
One more thing, heli!

Do you know how I can send more than one file ?
0
 

Author Comment

by:casexpert
ID: 1967272
Oh, heli!

I encountered, that my (always opend) MS Exchange closes, when I use your code.

How can I permit this ?
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1967273
Blimey, I missed my chance there didn't I?

I would guess to add more attachments you would repeat the code:

                 Set MapiAttachment = MapiMessage.Attachments.Add
                  With MapiAttachment
                      .Name = "Customers.txt"
                      .Type = mapiFileData
                      .Source = "C:\Examples\Customers.txt"
                      .ReadFromFile filename:="C:\Examples\Customers.txt"
                      .position = 2880

                  End With

with different values, or maybe put it into a loop with passed parameters.

I don't know why exchange would close. Have you tried experimenting with the line:

 .Send showdialog:=True

by making it false. Otherwise try stepping through the code and seeing where it closes. My guess is it would be at the set obj=nothing line. I'll have a look when I get home tonight as I don't have exchange here at work.


0
 

Author Comment

by:casexpert
ID: 1967274
No, heli, it's ok. The obj=nothing line is the cause.

Post me something as answer so I can credit you the points
0
 
LVL 8

Accepted Solution

by:
Helicopter earned 150 total points
ID: 1967275
Thanks, I'm glad it works.
0
 

Author Comment

by:casexpert
ID: 1967276
Maybe you could tell me a solution for another problem:

How can I indicate, that I receive a special type of Mail and automatically save the Attachment file of this Mail in a specified folder

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now