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!

sendObject in Access 2000 2

Status
Not open for further replies.

MatthewP

Programmer
Jan 16, 2001
176
0
0
GB
I just upgraded my Access 97 database to 2000, and the sendObject - sending a string to an email no longer works.

I checked the help, and it said I needed mapivim.dll and pointed me to buy a microsoft book about how to do it!

Useful..

Is there any easier way I can get this feature working again in Access 2000?

Cheers,
Matt.
 
I gave up on the SendObject function in Access 2000 and automated Outlook instead - much more reliable results.

Here is my function. It uses late-binding, so you don't need to set a reference to any particular version of Outlook (not tested earlier than Outlook 2000). The attachments I send are usually shortcuts (.LNK files) so there is a bit of extra code to strip the .LNK from the description as viewed in the email. The two commented lines Dim OL & MyMailItem) are there for assistance while developing - I set a reference to Outlook and swap the Dim lines so I get IntelliSense prompting & strict compiler checking, then set them back again afterwards.

Code:
Public Function SendEmail(MailTo As String, CCTo As String, BCCTo As String, Subject As String, Message As String, Optional EditBeforeSending As Boolean = False, Optional Attachment As String) As Boolean
Const olByValue = 1
Dim OL As Object
Dim MyMailItem As Object
Dim AName As String
Dim A As Long
'Dim OL As Outlook.Application
'Dim MyMailItem As Outlook.MailItem

Const olMailItem = 0

Set OL = CreateObject("Outlook.Application")
Set MyMailItem = OL.CreateItem(olMailItem)
With MyMailItem
    .To = MailTo
    .CC = CCTo
    .BCC = BCCTo
    .Subject = Subject
    If Attachment <> &quot;&quot; Then
        If Dir(Attachment) <> &quot;&quot; Then
            'Display it without the '.lnk'
            AName = Attachment
            A = InStr(1, AName, &quot;\&quot;)
            While A <> 0
                AName = Mid$(AName, A + 1)
                A = InStr(1, AName, &quot;\&quot;)
            Wend
            A = InStr(1, AName, &quot;.&quot;)
            If A > 0 Then
                AName = Left$(AName, A - 1)
            End If
            If AName = &quot;&quot; Then AName = Attachment 'Make sure we have something at least
            .Attachments.Add Attachment, olByValue, 1, AName ' Add A Copy (Not Shortcut)
        End If
        .body = vbCr & Message
    Else
        .body = Message
    End If
    If EditBeforeSending Then
        .Display
    Else
        On Error Resume Next
        .Send
        If Err.Number <> 0 Then
            MsgBox &quot;Email not sent!&quot;, vbExclamation
            Err.Clear
        End If
        On Error GoTo 0
    End If
End With

Set MyMailItem = Nothing
Set OL = Nothing
End Function
 
Dear Norris,

I gave you a star because I felt that your post was helpful to me.

Two Questions for you:
1) Do you also have examples on how to write and read too other outlook objects? I would love to see an example of retrieving and writing Appointments, Tasks and Contacts.
Can you cut and paste examples here or email to me at hap@fcs-software.com ?

2) I have searched all over for books or documentation for the Outlook, Word and Excel Objects. Do you know where information on how to program these objects (in VBA) can be found/purchased?

Many Thanks,
Hap [2thumbsup]



Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
The well-known, famous SendObject bug in Access 2000...

SendObject runs just once, then doesn't, without any error...been there, seen it.

I got rid of it by playing a little with the list separator in regional settings (set it to ;). Moreover, if you send emails to more than one recipient, make sure they are separated by ;, not by ,.

It started working after that.

It may be of help.

If you use Outlook as email client, go for Automation. If not, try my suggestion

Good luck


[pipe]
Daniel Vlas
Systems Consultant

 
We use Eudora, so I really need to get this working.

I have written a stand alone visual basic program that reads the database and creates an email, which seems to work OK except for one thing - Eudora doesn't understand the Chr(10), Chr(13) and vbCrLF - so despite when I MsgBox it to the screen in VB it looks fine, in Eudora I just get a constant string of text. Any ideas how I can get rid of this? Or other suggestions?

Thanks,
Matt.
 
BTW - the entire reason for upgrading is that I need to use some VB6 code in a module, just the split and substring functions actually! If I can include something in the references in 97 just to get this working I'll be fine!

Thanks,
Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top