Solved

Sending individual emails from MSAccess

Posted on 2008-10-07
10
236 Views
Last Modified: 2012-05-05
Hello Experts,

I am trying to send out individual emails to each store letting them know what time the shipment will arrive, using Microsoft Access 2003
Table name is "DelNotification". Fields are "StoreNo", "StartTime", "EndTime", "ShipDate".
Email address will be the 4 digit StoreNo and _store@domain.com
example: if StoreNo is 1234, email address is 1234_store@domain.com

the body of the letter will include the StartTime, EndTime and ShipDate. these are the only fields that vary.
and each store will have a different delivery time, that is why it will send out different information for every email.

All the fields will be entered from a form, and user will push a button and it will send the email to all stores.
Hope this makes sense... any help would be greatly appreciated
0
Comment
Question by:Boething
  • 5
  • 5
10 Comments
 
LVL 26

Expert Comment

by:dannywareham
ID: 22662326
This should get you started.



Dim mySQL as String
Dim myRST as ADODB.Recordset
Dim myEmail as String
Dim myStore as String, myStart as String, myEnd as String, myShip as String
 
 
mySQL = "SELECT [StoreNo], [StartTime], [EndTime], [ShipDate] FROM [DelNotification]"
        Set myRST = New ADODB.Recordset
        myRST.Open mySQL, CurrentProject.Connection
            Do While Not myRST.EOF
 
myEmail = myRST.field("StoreNo") & "@domain.com"
myStore = myRST.field("StoreNo")
myStart  = myRST.field("Start Time")
'etc
 
'now build mail
docmd.SendObject acNoObject  'amend as necessary
 
  myRST.MoveNext
 Loop
myRST.Close
Set myRST = Nothing

Open in new window

0
 

Author Comment

by:Boething
ID: 22662805
Hello Danny,

sorry, forgot to mention that I have always created my queries from design view.
where do I put this code?
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 22662992
Create a form.
Add a command button.
open properties on the command button and select the On_Click event.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:Boething
ID: 22663978
would I be able to do this from a Macro??
I tried using the SendObject but it came up as an attachment instead of the body of the letter.
If anyone can show me how to modify this so it will come up as the body of the letter, I think I could work around it.

Danny, I did try using the code you provided, but could not make heads or tails with it. I am not a programmer and do not understand how to modify it.
I got this error when I ran the code
"item cannot be found in the collection corresponding to the requested name or ordinal"
0
 
LVL 26

Accepted Solution

by:
dannywareham earned 500 total points
ID: 22664273
This should work as is.
If you create a module and paste this in.

Then you can use a macro to runCommand on  SendEmails()

That should do you
Public Function SendEmails()
Dim mySQL As String
Dim myRST As ADODB.Recordset
Dim myEmail As String
Dim myStore As String, myStart As String, myEnd As String, myShip As String, myMessage As String
 
 
mySQL = "SELECT [StoreNo], [StartTime], [EndTime], [ShipDate] FROM [DelNotification]"
        Set myRST = New ADODB.Recordset
        myRST.Open mySQL, CurrentProject.Connection
            Do While Not myRST.EOF
 
myEmail = myRST.Fields("StoreNo") & "@domain.com"
myStore = myRST.Fields("StoreNo")
myStart = myRST.Fields("StartTime")
myEnd = myRST.Fields("EndTime")
myShip = myRST.Fields("ShipDate")
 
'build message
myMessage = "Store: " & myStore & vbCrLf
myMessage = myMessage & "Start Time: " & myStart & vbCrLf
myMessage = myMessage & "End Time: " & myEnd & vbCrLf
myMessage = myMessage & "Ship Date: " & myShip & vbCrLf
 
'now build mail
DoCmd.SendObject acSendNoObject, , acFormatRTF, myEmail, , , "Email Subject here", myMessage, False
 
 
  myRST.MoveNext
 Loop
myRST.Close
Set myRST = Nothing
End Function

Open in new window

0
 

Author Comment

by:Boething
ID: 22664540
I am getting a
runtime error 3265.
"item cannot be found in the collection corresponding to the requested name or ordinal"
followed by end or debug.
when I click on debug,
myEmail = myRST.Fields("test@domain.com") is highlighted
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 22664652
That isn't in my code....

The line says:

myEmail = myRST.Fields("StoreNo") & "@domain.com"


StoreNo is the name of your field in your table.
0
 

Author Comment

by:Boething
ID: 22664773
Oh, you're right. I changed it for testing, not realizing it would mess up the code.
works great. Thanks
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 22667342
Glad you got it sorted.
:-)
0
 

Author Comment

by:Boething
ID: 22671262
Danny,
I did not test it out completely.
If I put 3 lines on my table, the first email is good.
but the 2nd email has 2 messages, the second one appends to the first one.
and the 3rd email has 3 messages.

is the code missing something to reset? or did I mess something up?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Object Variable or Block Variable Not Set - Adobe Acrobat 31 66
Spell checker for VBA 4 29
VBA modules import 4 57
Access Creating a report using a date range 11 10
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question