473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sending Email Attachment, wrong Outlook Version

I have some code, from this group (many thanks) that sends an
attachment to an email.

The following:

Dim objNewMail As Outlook.MailItem
Dim golApp As Outlook.Application
Dim initializeOutlook As Boolean

requires Microsoft Outlook xx Object Library in the references.

My problem is that I have Oulook 2003 (xx = 11), the PC's that I want
to run it on has Outlook 2000 or 97 (!), and more of a problem only
Access 2000 runtime.

When I load up the database on their PC because it can't find the
reference it's looking for (Outlook 11) I get a runtime error, and
Access closes. I can't change the reference to their version of
Outlook as they, as mentioned, only have the runtime.

So for now I've removed the code / reference.

My question is "How can I get around this?" I thought I was being very
clever, now I'm stumped. I need to have code that will email a file,
that is generated within Access, as an attachment.

I'd really like some generic code that would use whatever email program
they have, I guess.

Any ideas?

Thank you,

Jon

Jan 25 '06 #1
5 2853
J-P-W wrote in message
<11**********************@o13g2000cwo.googlegroups .com> :
I have some code, from this group (many thanks) that sends an
attachment to an email.

The following:

Dim objNewMail As Outlook.MailItem
Dim golApp As Outlook.Application
Dim initializeOutlook As Boolean

requires Microsoft Outlook xx Object Library in the references.

My problem is that I have Oulook 2003 (xx = 11), the PC's that I want
to run it on has Outlook 2000 or 97 (!), and more of a problem only
Access 2000 runtime.

When I load up the database on their PC because it can't find the
reference it's looking for (Outlook 11) I get a runtime error, and
Access closes. I can't change the reference to their version of
Outlook as they, as mentioned, only have the runtime.

So for now I've removed the code / reference.

My question is "How can I get around this?" I thought I was being very
clever, now I'm stumped. I need to have code that will email a file,
that is generated within Access, as an attachment.

I'd really like some generic code that would use whatever email program
they have, I guess.

Any ideas?

Thank you,

Jon


Try late binding.

It means you remove the references, and declare like this

Dim objNewMail As object 'Outlook.MailItem
Dim golApp As object 'Outlook.Application

In stead of using the New keyword when instantiating, you use

set golapp = createobject("outlook.application")

- or do a combination/test for existing open app through the getobject
function

Note - Outlooks specific constants must be replaced. (they are often
prefixed with "ol") For instance a line like this

set objNewMail = golApp.createitem(olMailItem)

should be replaced with something like

set objNewMail = golApp.createitem(0)

--
Roy-Vidar
Jan 25 '06 #2
Great, thanks I'll give that a go!

Regards, Jon

Jan 25 '06 #3
Outlook is a gnarly program; MS recommends the use of CDO to send
e-mail

This sample code will send a report as html. It should run in
Northwinds.
If you take a little time and study it, you can probably modify it to
meet your needs.
It has no magic to guess your smtp server, or other parameter.
If you write it without specifying many of the properties it will just
fall back on Outlook Express default account settings, if these exist.

It should work with Windows 2000 or Windows XP.

Option Explicit

Public Sub SendReportAsHTML( _
ByVal ReportName As String, _
ByVal SMTPServer As String, _
ByVal SendUserName As String, _
ByVal SendPassword As String, _
ByVal SendEmailAddress As String, _
ByVal Subject As String, _
ByVal Recipients As String, _
Optional ByVal NumberofPagesAllowed As Long = 10)

Dim Buffer As String
Dim Position As Long
Dim FileNumber As Integer
Dim HTML As String
Dim HTMLFullPath As String
Dim iCfg As Object
Dim iMsg As Object
Dim Skelton As String
Dim TempDirectory As String
Dim Truncate As Long

Set iCfg = CreateObject("CDO.Configuration")
Set iMsg = CreateObject("CDO.Message")

TempDirectory = Environ$("temp")
If Len(TempDirectory) = 0 Then TempDirectory = CurDir$()
TempDirectory = TempDirectory & "\"
Skelton = Format(Now(), "mmmddyyyyhhnnss")
HTMLFullPath = TempDirectory & Skelton & ".html"

DoCmd.OutputTo acOutputReport, ReportName, acFormatHTML, HTMLFullPath

HTMLFullPath = Dir$(TempDirectory & Skelton & "*.html")
While Len(HTMLFullPath) <> 0 And NumberofPagesAllowed <> 0
HTMLFullPath = TempDirectory & HTMLFullPath
FileNumber = FreeFile()
Open HTMLFullPath For Binary As #FileNumber
Buffer = String(LOF(FileNumber), vbNullChar)
Get #FileNumber, , Buffer
Close #FileNumber
Position = InStr(Buffer, "</TABLE>")
While Position <> 0
Truncate = Position
Position = InStr(Truncate + 1, Buffer, "</TABLE>")
Wend
HTML = HTML & Left(Buffer, Truncate + 7)
HTML = HTML & "<hr>"
Kill HTMLFullPath
HTMLFullPath = Dir$()
NumberofPagesAllowed = NumberofPagesAllowed - 1
Wend

If Len(HTMLFullPath) <> 0 And NumberofPagesAllowed = 0 Then _
HTML = HTML & "<br><b>Partial Report: Additional Pages not Shown"

With iCfg.Fields
..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
SMTPServer
..Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")
= 1
..Item("http://schemas.microsoft.com/cdo/configuration/sendusername") =
SendUserName
..Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") =
SendPassword
..Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress")
= SendEmailAddress
..Update
End With
With iMsg
..Configuration = iCfg
..Subject = Subject
..To = Recipients
..HTMLBody = HTML
..Send
End With

SendReportAsHTMLExit:
Close
Set iMsg = Nothing
Set iCfg = Nothing
Exit Sub

SendReportAsHTMLErr:
With Err
MsgBox .Description, vbCritical, "Error " & .Number
End With
Resume SendReportAsHTMLExit

End Sub

Private Sub TestSendReportAsHTML()
SendReportAsHTML "Products By Category", "mail.yoursmtpserver.com",
"youremail.com", "thepassword", "thesender", "Testing
SendReportAsHTML", "th*********@hisherdomain.com"
End Sub

Jan 25 '06 #4
Hi Lyle,
although this may be very useful for another project, I guess not in
this case as the clients send all mail through an exchange server, and
don't even know the relevant passwords, that for the IT bods to know!!!
Regards
Jon

Jan 26 '06 #5
Lyle sorry, I will read the reply better next time... now I note "If
you write it without specifying many of the properties it will just
fall back on Outlook Express default account settings, if these exist."
Many thanks
Jon :{

Jan 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Sven Templin | last post by:
Hello all, our configuration is as following described: - OS: Windows 2000 - Apache server 1.3 - Php 3.8 - MS outlook client 2000 _and_ no SMTP server available in the whole intranet.
2
by: Tom Dauria | last post by:
I have a Access database application that sends email through Outlook. A few years ago we started having a problem where it would ask for each and every email being sent whether you want to give...
4
by: Robert McNally | last post by:
Hello, I'm currently learning c# and have been trying to write a simple program with sockets. The problem is i'm trying to send an email with an attachment, (which is the program itself) by...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
1
by: handokowidjaja | last post by:
Hi All, Several weeks ago i started a topic with the same subject, however the solutions provided was for using MS Outlook (fullblown version). I finally found something that works directly with...
6
by: Rushwire | last post by:
Does anybody know how to send a meeting request using an ics/vcs (VCalendar) attachment from an asp.net page. I don't want my users to have to double click on the attachment but rather that it is...
2
by: Kosmos | last post by:
Alright so I've got this Outlook code written in VBA in Access. The first part, which works, records information about appointment times based on the required days before notification of certain...
7
by: Paridevi | last post by:
Hai , i want to send email in .Net Using OutLook Express,My Project is Web Application using vb.Net 2003 with SQL Server 2000.I have searched a lot in Google, but ican't get any...
2
by: Erik Witkop | last post by:
So I have been trying to get this to work all day. I can't get a local file on my web server to attach to an email. Right now I have it printing out in the body of the email. Please help me with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.