Button Programming - Send an HTML Email

G

Guest

I click a button and suppose to open an email. The body it is suppose to use
is HTML and is suppose to get the content from a file located on my pc.

Me.PDFEmailCreator is the name of the unbound pull down I'm using, to obtain
the name of the file to use.

Here is my code. It isn't working, anyone know why?


Dim objOApp As Object
Dim objOMessage As Object
Dim txtDir As String
Dim fso As Object
Dim ts As Object

Const olMailItem = 0
txtDir = "C:\Documents and Settings\Curtis
Stevens\Desktop\Applications\USMS\Emails\"

Set objOApp = CreateObject("Outlook.Application") 'created the
application here
Set objOMessage = objOApp.CreateItem(olMailItem) ' and last here is
an Mail Item
Set fso = CreateObject("Scripting.FileSystemObject")

'if Me.PDFEmailCreator is the file which you hold the email content
Set ts = fso.OpenTextFile(txtDir & Me.PDFEmailCreator, spForReading)

txtbody = txtDir & Me.PDFEmailCreator

With objOMessage
.to = Me.BizEmail
.Subject = "Application"
.htmlbody = ts.ReadAll 'read all content of file
Me.PDFEmailCreator
.Display
End With


Thanks!!
Curtis
 
D

Douglas J. Steele

What does "isn't working" mean?

I don't do Outlook Automation (we don't use Outlook), but you do seem to be
missing the Send method on objOMessage. (Most samples I've seen also invoke
the Save method before the Send method)
 
G

Guest

I have the .display, so it pops up an email with everything in it. My old
version works, but not this one, it doesn't pop up an email like it should
for me to review & send. I have a file in the Emails folder called test.txt.

I tried using both test and test.txt in my pull down as the name file and
nothing.

It errors and goes to this line:

Set ts = fso.OpenTextFile(txtDir & Me.PDFEmailCreator, spForReading)
 
D

Douglas J. Steele

You're using Late Binding. That means Access doesn't know anothing about
spForReading.

Either declare it as constant (equal to 1), or simply replace it with 1 in
that line of code.
 
G

Guest

Bingo! What does the 1 do, for what?

Also, I want to refer to their name in the amil, like Dear Me.Contact. But
just Me. Contact in the text file (along with my other text) doesn't work,
just puts me.contact instead of the data in my database.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top