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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send e-mail from access databases 65

Status
Not open for further replies.

tpowers

Technical User
Nov 2, 2002
153
US
Now I am a new guy on the block, so bear with me. I have a form that users are entering client information into all day, and I have been asked to set the database up so that when the are done entering the record that it will automaticlly send the client a confirmation e-mail that the record as been recieved and entered into our database.

Again I am new at this so if so one as a clue of how to do this that would be great.


 
Try:
Dim objOutLook
Set objOutLook=CreateObject("OutLook.Application")

HTH
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Well see this is what I have going

Dim strEmail, strbody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
'**creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(olMailItem)

What do you think?
 
Your code looks fine to me, should work if Outlook is referenced, if no-one has any better ideas then maybe reparing Office on the problem machines might be worth a try?

Sharon
 
Dim the Outlook objects as Variant-like below:

Dim strEmail, strbody As String
Dim objOutlook
Dim objEmail
'**creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(olMailItem)

I met this error and this is how I got rid of it.
A variation is:

Dim objOutlook As Object
Dim objEmail As Object

HTH [pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
I am still getting an error message that states "Compile Error: Can't Find Projectr or Library, but now the code fails at the "olMailItem" of
Set objEmail = objOutlook.CreateItem(olMailItem)

Do you know why

 
cavery:Lotus Notes question

Here's a Lotus Notes email routine. It requires that the user be logged into Notes, otherwise it prompts for the password. Enjoy.
'**************************

Public Function EmailUsers()

Dim Session As Object
Dim db As Object
Dim doc As Object
Dim rtf1 As Object
Dim eo1 As Object


'Start new Lotus Notes Session
Set Session = CreateObject("Notes.NotesSession")
Set db = Session.GetDatabase("", "")
'Open Mail Database. This will prompt for a password if not already open-
'For full automation, Notes should already be open.
Call db.OpenMail
'Make new document
Set doc = db.CreateDocument

'Build e-mail
With doc
.Form = "Memo"
.SaveMessageOnSend = True
.SendTo = "MyRecipients"
.cc = "ccRecipients"
.Subject = "BlahBlah"
Set rtf1 = .CreateRichTextItem(doc, "Body")
'Import Text
Call rtf1.AppendText("Body Text " & Variable & "Here")
'Attach Files
Set eo1 = rtf1.EmbedObject(1454, "", "C:\Path\File")
'Send Mail
Call .Send(True)
End With
'Deallocate Objects
Set rtf1 = Nothing
Set doc = Nothing
Set Session = Nothing
End Function
 
Can you tell me how this last entry is going to help me.


Thank you
 
tpowers:
That's for cavery, from earlier in the thread. Sorry for the non-sequitur, but I figured I'd throw it out there.
 
nathan1967,

First let me say you have done an excellent job in helping out here....I would give you a star, but you are already maxed out..... :)

Now, I just want to say one thing, since in one of your first couple of posts you said this process helps you learn as much as it helps someone else....

My comment lies in a streamlining of your variable declarations....you are using:


Dim email, ref, origin, destination, notes As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem


This is the same as:

Dim email as Variant
Dim ref as Variant
Dim origin as Variant
Dim destination as Variant
Dim notes as String
Dim objOutlook as Outlook.Application
Dim objEmail as Outlook.MailItem

And I don't think this was your intent. I beleive your intent was to make the first five variables, which you included on one line, all defined as string. And that is what they should be. But Access won't read comma-separated definitions that way....you would have to use:

Dim email as String, ref as String, etc....

Your declaration works, but as I hope you are aware...variants are much more combursome in terms of processing to work with as they have to be evaluated for their data type at every use. In an instance such as this, probably not a big deal...but it is better to learn it the correct way from the start then develop bad habits early on....

Again, don't take this the wrong way...merely a bit of constructive help to better yourself and also for everyone else's benefit.
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Object required, thanks,.....few other questions, do I need a command button? and also does this line of code go in a module? and last but not least, will this code email reports? as in graphs?

Thanks,
Clark
 
cavery:
1) Nope. You can run it from code, or on an event, or timer, etc. by calling the function.
2)As it's written, it should go in a module and can be called from anywhere in the DB with EmailUsers(), but you can transplant the code (all but the function declaration) anywhere you want.
3) There's a thread somewhere in here about exporing Chart objects as Jpegs, and when you export reports to 'Word' they are saved as .RTF (rich text) files. So, you can either export the report/chart and attach it (withe the EmbedObject command, above) or try to figure out how to get the rich text from the report into the message body, but that sounds like a pain in the ass.
 
mstrmage1768,

Thanks for your praise! and Thanks for your comments.

You are correct in your assumption. My intent was not to declare Variants. I guess I didnt catch it since everything worked.

Thanks again for pointing that out. :) Have A Great Day!!!,

Nathan
Senior Test Lead
 
Hi, I'm going to have a post a star as well. This thread has answered all the questions I've ever had about emailing from Access and then some.

Thanks alot!
 
I am using the following code to put an email function into my access file.

Private Sub e_mail_Click()
Dim strEmail, strBody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

'**creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'**************************************************************
'*create string with email address

strEmail = txtEmail

strBody = txtTDate & Chr(13) & Chr(13)
strBody = strBody & "Dear " & txtFName & " " & txtLName & "," & Chr(13) & Chr(13)
strBody = strBody & "We have received your information and are processing it promptly. Please review the information" & _
" below to ensure our accuracy." & Chr(13) & Chr(13) & Chr(13)
strBody = strBody & "Name: " & txtFName & " " & txtLName & Chr(13)
strBody = strBody & "Address: " & txtAddress & Chr(13)
strBody = strBody & "City, State, Zip: " & txtCity & ", " & txtState & ". " & txtZip & Chr(13)
strBody = strBody & "Country: " & txtCountry & Chr(13) & Chr(13)
strBody = strBody & "Account Number: " & txtAccount & Chr(13)
strBody = strBody & "Schedule Date: " & txtSDate & Chr(13)
strBody = strBody & "License: " & txtLicense & Chr(13)
strBody = strBody & "Issuing Address: " & txtIssueAddress & Chr(13)
strBody = strBody & "Issue Code: " & txtIssueCode & Chr(13)
strBody = strBody & "Issue Code Description: " & txtIssueCodeDescrip & Chr(13) & Chr(13)
strBody = strBody & "Special Notes: " & txtNotes & Chr(13) & Chr(13)
strBody = strBody & "Sincerely," & Chr(13) & Chr(13)
strBody = strBody & "Acme Corporation"

'***creates and sends email
With objEmail
.To = strEmail
.Subject = "Your information has been received"
.Body = strBody
.Send
End With

Set objEmail = Nothing
'****closes Outlook. remove if you do not want to close Outlook
objOutlook.Quit

Exit Sub

End Sub

However when i go to use the function, a run-time error is displayed and .Send is highlighted in yellow.

The run-time error is '-2044706811 (86204005)' "There must be at least one name or Distribution list, in the To, Cc, or Bcc Box."

Please help me!!! :)
 
Hi Welshspoon,

Where are you defining your email address? In the code above, the email address is being pulled from a form textbox called txtEmail.

The error you are receiving is stating that you do not have a defined email address.

Try to debug and see what you are passing to the strEmail variable. Have A Great Day!!!,

Nathan
Senior Test Lead
 
Hi, i try this code to send e-mails using Netscape 7.01
The problem is that the senders e-mail address does not appear in the created e-mail.
"ref", "origin" and "destination" appear in the subject line of netscape and "note" in the body.
Can someone help me ?

Thank you,
Michael

'****begin code****
Private Sub Command10_Click()
Dim email, ref, origin, destination, notes As String

'***set references from your form
email = Me!email
ref = Me!ref
origin = Me!origin
destination = Me!destination
notes = Me!notes

'***set up the transaction that will format and send email
'***True at the end of the statement allows the email to be
'***edited before sent. change to False, and the email is
'***sent without edit
DoCmd.SendObject acSendForm, , acFormatTXT, email, , , ref & " " & origin & " " & destination, notes, True

End Sub

'****end code****




 
Hi guys I use the send object feature which is just great. One question though, how can i set the importance to either low or high?
FYI: I use Microsoft Outlook.
 
Hiya!! Sorry 2 bug u again, but now i got the button working for my e-mails, i have a problem with outlook opening.

When i click the button, outlook appears in the start bar, then goes almost straight away, but the program doesn't open.

What have i done wrong? Please help
 
Hiya!! im leaving a msg 2 say i solved my last problem lol i was being silly.

i got a new q though. i wanna include information from a subform in my e-mails, but my subform contains more than 1 item of data in each coloumn. What i want to do is to only include selected items of data.

Basically i want only records from the subform which fit a certain criteria to display in the e-mail. i.e. only records which has no in a certain field.

please help me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top