473,378 Members | 1,580 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,378 software developers and data experts.

Email records

I am using Access '03. I have a very basic table and form set up to quote customers. I'd like to set up a command button on the form to email a specific record to a specific customer as the body of the Outlook message, not as an attachment. Is this possible? If not, any suggestions would be appreciated...

Paul
Mar 29 '07 #1
15 2864
Denburt
1,356 Expert 1GB
I use CDONTS for this but the coding is indepth there may be other ways but I am a bit tired I will sleep on this and see if there may be a less complicated method.
Mar 30 '07 #2
I am using Access '03. I have a very basic table and form set up to quote customers. I'd like to set up a command button on the form to email a specific record to a specific customer as the body of the Outlook message, not as an attachment. Is this possible? If not, any suggestions would be appreciated...

Paul
Hi Paul,

I am looking to do the same thing. I want to send an email with several pieces of data from a specific record pasted into the body, not as an attachment. Did you ever get a response about how to do this simply?

GB
Sep 4 '07 #3
Denburt
1,356 Expert 1GB
My apologies at such a delay. Let me see if we can get you going. There are so many variables depending if you using exchange server etc. This is a VERY broad question, with not much information. Here is a script that you should be able to modify to help get you going. Mind this though the method I am showing uses HTML email so if they view the email in plain text it will look much different.

Expand|Select|Wrap|Line Numbers
  1. Dim strTo As String, strFrom As String
  2. Dim stSub As String ' Subject
  3. Dim stMsg As String ' Body of Message
  4. Dim stRpt As String ' Name of Report
  5. Dim strCC As String
  6. Dim strBcc As String
  7. Dim iMsg As New CDO.Message
  8. Dim iconf As New CDO.Configuration
  9. Dim Flds
  10. Dim fso, ts, tsR, Cnt(3)
  11.  
  12. strTo = "1@2.somemail.com"
  13. strCC = "Only if you want"
  14. strBcc = "Alwys include myself I like to know it goes out." 'More or less using this as a backup since if it error out I get that email also.
  15. strFrom = "WhoEver"
  16. stSub = "...Orders Report..."
  17.  
  18. 'Here I open the report and export it as HTML
  19. DoCmd.OpenReport "My Orders", acViewPreview
  20. DoCmd.OutputTo acOutputReport, "StupidReport", acFormatHTML, Application.CurrentProject.Path & "\RD.HTML", False
  21. Const ForReading = 1, ForWriting = 2
  22.  
  23. 'Here I open the HTML and make any known needed changes. Exporting to HTMl always screws up lines etc.
  24.  Set fso = CreateObject("Scripting.FileSystemObject")
  25.  Set ts = fso.OpenTextFile(Application.CurrentProject.Path & "\RD.HTML", ForReading, False) '.CreateTextFile(vFile)
  26.  
  27.  
  28. tsR = ts.ReadAll
  29. tsR = Replace(tsR, "&nbsp", "&nbsp")
  30. tsR = Replace(tsR, "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 >" & vbCrLf & "<TR HEIGHT=18 >" & vbCrLf & "<TD WIDTH=687  ALIGN=LEFT > <BR></TD><TD WIDTH=97  ALIGN=CENTER ><B><I><FONT style=FONT-SIZE:11pt FACE=""Times New Roman"" COLOR=#000080>AEC</FONT></B></I></TD>", _
  31.                     "<TABLE style=""border-bottom: solid"" CELLSPACING=0 CELLPADDING=0 >" & vbCrLf & "<TR HEIGHT=18 >" & vbCrLf & "<td Width=775 colspan=""7""></td><TD colspan=""2"" style=""border-top: solid;border-left: solid;;border-right: solid;"" WIDTH=67  ALIGN=CENTER ><B><I><FONT style=FONT-SIZE:11pt FACE=""Times New Roman"" COLOR=#000080>AEC</FONT></B></I></TD>")
  32.  
  33. Set ts = fso.OpenTextFile(Application.CurrentProject.Path & "\RD.HTML", ForWriting, True)
  34.  ts.write (tsR)
  35.   ts.Close
  36.  Set ts = Nothing
  37.  
  38. Const cdoSendUsingPort = 2
  39. Const strSmartHost = "EchangeServerI
  40.  
  41. Set iMsg = CreateObject("CDO.Message")
  42. Set iconf = CreateObject("CDO.Configuration")
  43.  
  44. ' Set the configuration fields.
  45. Set Flds = iconf.Fields
  46.  
  47. ' Set the proxy server to be used.
  48. Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
  49.  
  50. ' TODO: Set "someproxy:80" to the name of your proxy server.
  51. 'Flds("http://schemas.microsoft.com/cdo/configuration/urlproxyserver") = "SomeExchangeSeverAdddy"
  52. Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost
  53.  
  54. ' Set if this is a local server.
  55. 'Flds("http://schemas.microsoft.com/cdo/configuration/urlproxybypass") = "<local>"
  56.  
  57. ' Set the option to retrieve the latest content directly from the server.
  58. Flds("http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion") = True
  59. Flds.Update
  60.  
  61. ' Set the message properties.
  62. Set .Configuration = iconf
  63. ' Create the MIME representation of the Web page in the message.
  64. ' TODO: Change the To and From fields to valid e-mail addresses.
  65. '.CreateMHTMLBody = "http//whatever.com"
  66. .HTMLBody = tsR 
  67. '.CreateMHTMLBody Application.CurrentProject.Path & "\RD.HTML"
  68. .To = strTo
  69. .CC = strCC
  70. .BCC = strBcc
  71. .From = strFrom
  72. .Subject = stSub
  73. .Send
  74.  
  75. Set .Configuration = Nothing
  76. Set Flds = Nothing
  77. Set iconf = Nothing
  78. Set iMsg = Nothing
  79. Set fso = Nothing
  80.  
  81. End With
  82.  

As you can see I have many commands commented out as I didn't have a need for them, there are many more commands that are available, and I tried to bold the items you should change to suite your needs.. Hopefully you can make some heads and or tails out of it. Good luck. Let us know.
Sep 5 '07 #4
Thanks for the input,

I can created the htm file and save it but have problems with reading and re-writing it and getting it to the body of an OUTLOOK email. I don't really car about the TO, FROM etc. just want to dump the htm into the body of an OUTLOOK email.

The first line of code "Dim iMsg As New CDO.Message" returns a compile error "user-type not defined."

Also, my Access db is on a MS 2003 server, could this be the problem with cdo?

I am running MS 2000 and IIS using CDONTS for sending email but I need to keep Access 2003 on the 2003 server and LAN.
Sep 5 '07 #5
Denburt
1,356 Expert 1GB
As a side not I used this once to send an email to my boss telling him he was fired... :)

strFrom = "WhoEver"
It looked just like it came from the higher ups but I made sure I was nearby when he opened it.
Sep 5 '07 #6
Here's some code I use. I set up a form with the fields below. Form name is "Group Email" Button on click event uses this code. note you may need to set a referend in VB to the outlook library.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command61_Click()
  2.  
  3. Dim EmailApp, NameSpace, EmailSend As Object
  4. Dim MsgBody As String
  5. Dim Attachment As String
  6. Dim EmailAddress As String
  7. Set EmailApp = CreateObject("Outlook.Application")
  8. Set NameSpace = EmailApp.GetNamespace("MAPI")
  9. Set EmailSend = EmailApp.CreateItem(0)
  10.  
  11.  
  12. 'Attachment = [Forms]![Group Email]![AttachmentPath]
  13. EmailAddress = [Forms]![Group Email]![Text42]
  14.  
  15. MsgBody = "Dear " & Forms![Group Email]![Text62] & ":" & vbCrLf & vbCrLf & _
  16. Forms![Group Email]![Body] & vbCrLf & vbCrLf & ""
  17.  
  18. EmailSend.to = EmailAddress ' Put email address here
  19. EmailSend.Subject = [Forms]![Group Email]![Text71]
  20. EmailSend.Body = MsgBody
  21. 'EmailSend.Attachments.Add Attachment ' Change this to match your path
  22. 'EmailSend.Attachments.Add "c:\filetoattach.txt" ' Change this to match your path
  23. EmailSend.Display ' Remove this line if you don't want to see email
  24.  
  25. Set EmailApp = Nothing
  26. Set NameSpace = Nothing
  27. Set EmailSend = Nothing
  28.  
  29.  
  30. End Sub
Sep 6 '07 #7
NeoPa
32,556 Expert Mod 16PB
Thanks for the input,

I can created the htm file and save it but have problems with reading and re-writing it and getting it to the body of an OUTLOOK email. I don't really car about the TO, FROM etc. just want to dump the htm into the body of an OUTLOOK email.

The first line of code "Dim iMsg As New CDO.Message" returns a compile error "user-type not defined."

Also, my Access db is on a MS 2003 server, could this be the problem with cdo?

I am running MS 2000 and IIS using CDONTS for sending email but I need to keep Access 2003 on the 2003 server and LAN.
Goldenbear,

You're welcome to get whatever useful information you can from this thread. What you are not permitted to do is to divert this thread with your own questions or details.
You can ask for clarification, but diverting the thread is hijacking and is not allowed. If you need separate help with your problem you need to post your own question. Feel free to post a link to this thread if you feel that will be helpful.

MODERATOR.

PS. your error message probably comes from the library not being referenced.
Sep 6 '07 #8
NeoPa
32,556 Expert Mod 16PB
@goldenbear
You can also have a special dispensation to post a link to your new question in here so that the current list of members already subscribed will know immediately that it is a similar question.
Sep 6 '07 #9
Here's some code I use. I set up a form with the fields below. Form name is "Group Email" Button on click event uses this code. note you may need to set a referend in VB to the outlook library.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command61_Click()
  2.  
  3. Dim EmailApp, NameSpace, EmailSend As Object
  4. Dim MsgBody As String
  5. Dim Attachment As String
  6. Dim EmailAddress As String
  7. Set EmailApp = CreateObject("Outlook.Application")
  8. Set NameSpace = EmailApp.GetNamespace("MAPI")
  9. Set EmailSend = EmailApp.CreateItem(0)
  10.  
  11.  
  12. 'Attachment = [Forms]![Group Email]![AttachmentPath]
  13. EmailAddress = [Forms]![Group Email]![Text42]
  14.  
  15. MsgBody = "Dear " & Forms![Group Email]![Text62] & ":" & vbCrLf & vbCrLf & _
  16. Forms![Group Email]![Body] & vbCrLf & vbCrLf & ""
  17.  
  18. EmailSend.to = EmailAddress ' Put email address here
  19. EmailSend.Subject = [Forms]![Group Email]![Text71]
  20. EmailSend.Body = MsgBody
  21. 'EmailSend.Attachments.Add Attachment ' Change this to match your path
  22. 'EmailSend.Attachments.Add "c:\filetoattach.txt" ' Change this to match your path
  23. EmailSend.Display ' Remove this line if you don't want to see email
  24.  
  25. Set EmailApp = Nothing
  26. Set NameSpace = Nothing
  27. Set EmailSend = Nothing
  28.  
  29.  
  30. End Sub
Thanks slynch401k,

This worrked perfectly!!

GB
Sep 6 '07 #10
Denburt
1,356 Expert 1GB
Glad you got it. I did leave out the VBA reference to Microsoft CDO for windows.
Sep 6 '07 #11
NeoPa
32,556 Expert Mod 16PB
Den,

GoldenBear is NOT the OP (pauljhorak).
It's not a problem that he gets it, but let's not allow the thread hijack.

@GoldenBear,
You would be well advised in future to pay attention to moderators' posts - especially when they're directed at you.
You have now successfully diverted attention in this thread away from the OP's question to your own needs. This is not acceptable and will not continue (trust me on this one).
If you don't feel you can conform to the rules of this site then we'll just have to arrange that you are no longer in a position to break them.

MODERATOR.
Sep 6 '07 #12
Denburt
1,356 Expert 1GB
Your exactly right Neo.

Glad you got it GoldenBear.

Paul if your still with us has any of this helped you in any way?

Do you have any questions comments?
Sep 6 '07 #13
Your exactly right Neo.

Glad you got it GoldenBear.

Paul if your still with us has any of this helped you in any way?

Do you have any questions comments?
Denburt,

I thought my original questions/coomments were in line with the question Paul asked. I understood your comments when you first made them and had no intention of "diverting the thread" any further, once I understood the rules. Trust me it won't happen again! Don't forget I am a newbie.

Thanks again for the helpand have a great weekend.
Sep 7 '07 #14
NeoPa
32,556 Expert Mod 16PB
Denburt,

I thought my original questions/coomments were in line with the question Paul asked. I understood your comments when you first made them and had no intention of "diverting the thread" any further, once I understood the rules. Trust me it won't happen again! Don't forget I am a newbie.

Thanks again for the helpand have a great weekend.
GoldenBear,
We do appreciate that you're new to the site and we're glad you understand things a little better now.
A response to either of my earlier posts would have let us know that you understood though, and further posts would probably have been felt unnecessary.
That all said, I hope you had a great weekend and we really do hope you come back and benefit more from the site. It's what it's here for ;)
Sep 10 '07 #15
GoldenBear,
We do appreciate that you're new to the site and we're glad you understand things a little better now.
A response to either of my earlier posts would have let us know that you understood though, and further posts would probably have been felt unnecessary.
That all said, I hope you had a great weekend and we really do hope you come back and benefit more from the site. It's what it's here for ;)
OK, Yes
OK
YES
Thanks again
Sep 10 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kenshin | last post by:
Hey! I have another script where i pull all the information from the database and I want to send it to the person. What they do is they enter in their email, and if the email matches, than it will...
1
by: melsink | last post by:
I am trying find the best method to send email from my a contact access database. I would need to send group emails and save the transaction in access (is. time/date, subject of email and who the...
0
by: DS | last post by:
Hi Guys (and ladies): I have a parameter query in A2K that asks for records based on certain criteria. It returns the name and address fields of each record. I usually get about 5 to 10 records...
4
by: acni | last post by:
I have the following peice of code to try and send an email to selected contacts in my form.The problem is this line: StrStore = DLookup("", "qrySelectEmail", "??????") This looks up the email...
11
by: Chubbly Geezer | last post by:
Hi I'm in the process of converting an access db to vb2005. My old app has code that sends an email with a table attachment formatted to excel. I want to do the same within vb, i.e. create an...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
5
by: David | last post by:
Hi, I have an asp page which I am designing. On this page will be a set of records pulled from my db. These records will be displayed within a form. Each record will have a 'dropdown' displayed...
5
by: neeraj | last post by:
I have made a service which picks up records from a table which has following columns :From,to,subject,body,status The service, after picking up the records, loops through all the records and...
17
by: pradeep | last post by:
Hello all, How can i send email using PHP from my server ? Which settings are necessary ? please, guide me Thanks in advance.
1
by: Marie1106 | last post by:
Hi... I am hoping someone can help me... I have a subform which contains several records. One of the fields on the subform is "Email Address" I created a command button on the main form to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.