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

Need help for a loop

3
My qryDataToSend has following result:

KeyField Full_Name COURSE NPDD CENSUS LDTD Email
jd1001 John Doe ART 001-0101 1/15/2015 2/16/2015 3/17/2015 johndoe@fakeemail.com
jd1001 John Doe ART 023-0202 1/16/2015 2/17/2015 3/18/2015 johndoe@fakeemail.com
my1002 May Yee MATh 115-0303 7/1/2015 8/2/2015 9/3/2015 mayyee@thisemail.com
my1002 May Yee LAW 001-0505 8/1/2015 9/4/2015 10/20/2015 mayyee@thisemail.com
my1002 May Yee LAW 002-0303 9/1/2015 9/9/1015 10/30/2015 mayyee@thisemail.com

So I want to send an email to each instructor with his/her course in the outlook body. Following code result 1 email to the first faculty only with all 5 courses. I understand I need another loop (while keyField) to get it work but I cannot figure this out.Please help me with this outer loop. Thanks.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function send_mail()
  5.  
  6. 'Create application and mail objects
  7. Dim olApp As Object
  8. Dim objMail As Object
  9. Dim rs As DAO.Recordset
  10. Dim strID As String
  11. Dim strHeader As String
  12. Dim strText As String
  13. Dim strName As String
  14. Dim strEmail As String
  15.  
  16. strText = ""
  17.  
  18. Dim qd As QueryDef
  19. Set qd = CurrentDb.QueryDefs!qryDataToSend
  20.  
  21. 'Create a record set and run the query defined above
  22. Set rs = qd.OpenRecordset()
  23.  
  24. If (rs.BOF = True And rs.EOF = True) Then
  25. 'No record to process, should exit
  26. Else
  27. rs.MoveFirst
  28. End If
  29.  
  30.  
  31. Set olApp = CreateObject("Outlook.Application") 'Create a new instance
  32.  
  33.  
  34. 'Create e-mail item
  35. Set objMail = olApp.CreateItem(olMailItem)
  36.  
  37. 'Email header
  38.     strName = rs!Full_Name
  39.     strEmail = rs!email
  40. With objMail
  41.     .BodyFormat = olFormatHTML
  42.     .To = strEmail
  43.     .Subject = "Deadline Reminder"
  44.     .HTMLBody = "<!DOCTYPE html>"
  45.     .HTMLBody = .HTMLBody & "<html><head><style>table, th, td {border: 1px solid black}</style><body>"
  46.     .HTMLBody = .HTMLBody & "Dear " & strName & "," & "<p>"
  47.     .HTMLBody = .HTMLBody & "Below are your courses that the NPDD deadline is near."
  48.     .HTMLBody = .HTMLBody & "<table style='width:40%'>"
  49.     .HTMLBody = .HTMLBody & "<tr bgcolor='#AAAAAA'><td>COURSE</td>"
  50.     .HTMLBody = .HTMLBody & "<td align='center'>NPDD</td>"
  51.     .HTMLBody = .HTMLBody & "<td align='center'>CENSUS</td>"
  52.     .HTMLBody = .HTMLBody & "<td align='center'>LDTD</td></tr>"
  53. End With
  54.  
  55. strID = rs!keyfield
  56. While Not rs.EOF
  57. 'Add each entry to the body
  58.     With objMail
  59.         .HTMLBody = .HTMLBody & "<tr><td>" & rs!COURSE & "</td>"
  60.         .HTMLBody = .HTMLBody & "<td align='center'>" & rs!NPDD & "</td>"
  61.         .HTMLBody = .HTMLBody & "<td align='center'>" & rs!CENSUS & "</td>"
  62.         .HTMLBody = .HTMLBody & "<td align='center'>" & rs!LDTD & "</td></tr>"
  63.     End With
  64.         rs.MoveNext
  65. Wend
  66.  
  67. 'Add end of the body and send
  68. With objMail
  69.     .HTMLBody = objMail.HTMLBody & "</Table></Body>" & vbNewLine & "Signature" & vbCrLf & "Company"
  70.     '.send
  71.     .Display
  72. End With
  73.  
  74.  
  75. Set olApp = Nothing
  76. Set objMail = Nothing
  77.  
  78. End Function
  79.  
Aug 22 '15 #1
2 1018
songsu
3
I have it solved. Thank you.
Aug 23 '15 #2
Rabbit
12,516 Expert Mod 8TB
Can you post your solution in case someone else has the same problem?
Aug 23 '15 #3

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

Similar topics

47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
5
by: !TG | last post by:
I currently use Do while loop, but I'd rather use a For Loop though I have never gotten the hang of them. Would some one please be so kind as to show me how to loop through a recordset.
2
by: spidrw | last post by:
I have a system that lets users input service events (much like appointments at a Dr.'s office). Oftentimes a particular person will have 30 or 31 appointments in a month, as all events are...
14
by: Crimsonwingz | last post by:
Need to calculate a sum based on a number of factors over a period of years. I can use formula ^x for some of it, but need totals to carry over in the sum and have only been able to do this thus...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
7
by: gmou | last post by:
Dear group, I am building a translator from C++ into VB (and into C#). At the moment, I have a hard time figuring out the equivalent of a 'for' loop in VB. Given C++ code: for( int i=0;...
8
by: Dave | last post by:
I am trying to write an event-driven application with no main window that runs "forever". It waits on a named event and then displays a window depending on data pased in a memory-mapped file. I...
3
by: JDubP | last post by:
I know a bit about VBA in Excel, but not about looping records in Access 2003, so any help will be appreciated. I think if someone can send me some sample code, I can muddle my way through. (or if...
1
by: ed5195 | last post by:
All programming languages have a loop capability. Looping is the program logic’s ability to repeat one or more lines of code either: 1. A set number of times, a “for loop” (i.e. 10, 100, 500, 763 or...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.