473,748 Members | 7,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query to Initial Email?

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 have set up a Query to show only records that meet a
certain criteria...ther efore excluding all of the records that do not
meet this criteria (just for the record the criteria is any record
within my database that falls within two months of its "Due Date"
field). I need to find a way to cycle through all of these records
shown in the query and then automatically send an email to myself
notifying me that this particular record has almost expired...reach ed
its "Due Date".

Now I have already written the code to launch the "email" aspect of the
command...and this is working fine....I do, however, require some help
in automating the process....and was wondering if anyone could provide
me with the code to use, for example, within the form(s) "On Load"
event, that would initiate the "email" code I have already written
titled "SendMail"? ???? So essentially, if anyone could please spare the
time, would like to obtain some code that loops through all of the
records that query discovers to automate my "SendMail" command....it
would be very much appreciated!

Also does anyone know how to pass fields from a record into the body of
the email...i.e Outlook?
Kind Regards,

Liam

Jun 19 '06 #1
36 3064

Li****@awamarin e.com.au wrote:
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 have set up a Query to show only records that meet a
certain criteria...ther efore excluding all of the records that do not
meet this criteria (just for the record the criteria is any record
within my database that falls within two months of its "Due Date"
field). I need to find a way to cycle through all of these records
shown in the query and then automatically send an email to myself
notifying me that this particular record has almost expired...reach ed
its "Due Date".

Now I have already written the code to launch the "email" aspect of the
command...and this is working fine....I do, however, require some help
in automating the process....and was wondering if anyone could provide
me with the code to use, for example, within the form(s) "On Load"
event, that would initiate the "email" code I have already written
titled "SendMail"? ???? So essentially, if anyone could please spare the
time, would like to obtain some code that loops through all of the
records that query discovers to automate my "SendMail" command....it
would be very much appreciated!

Also does anyone know how to pass fields from a record into the body of
the email...i.e Outlook?
Kind Regards,

Liam


Liam,

OK, send a _single_ e-mail with the list of values from the query in
the body of the message....

you could create a function to create the message body (I'll call the
function fMsgBody), and then just change the message body assignment.

first, the fMsgBody function.

Function fMsgBody() As String
dim rsDue as dao.recordset
dim strList as string '---place to dump all the names in the
query

set rsDue=DBEngine( 0)(0).OpenRecor dset("qryDueMai ls")
do until rsDue.EOF
strList=rsDue.F ields("FirstNam e") & " " &
rsDue.Fields("L astName") & vbCrLf
rsDue.MoveNext
loop

fMsgBody="The following accounts are due:" & vbcrlf & strList

rsDue.Close
set rsDue=Nothing

End Function

then you'd just include this in your e-mail code.

Instead of the line that says
strMsg = Nz(Me!txtBody," ")

you could use:
strMsg = fMsgBody

(the function that builds the message body for you).

Then the rest of the code would be the same.

Clear as mud, right?

Jun 19 '06 #2
Thankyou so much for your reply....they are always extremely helpful!
Clear as mud...to me correct...hahah a...apologies BUT iam relatively
new too all of this...and unfortunately do lack the neccessary
experience...th e informaiton you have just provided me makes sense
however implementing this into my project is another story....
The code:
Function fMsgBody() As String
dim rsDue as dao.recordset
dim strList as string '---place to dump all the names in the
query

set rsDue=DBEngine( 0)(0).OpenRecor dset("qryEmail" )
do until rsDue.EOF
strList=rsDue.F ields("IMO Number") & " " & rsDue.Fields("V essel Name") & " " & ("Date of Issue") & " " & ("Due Date") & vbCrLf
rsDue.MoveNext
loop

fMsgBody="The following accounts are due:" & vbcrlf & strList

rsDue.Close
set rsDue=Nothing

End Function


Where about am I surposed to place this code...and how does this
initiate my "SendMail" function? Does this just pass the variables to
the "SendMail" function I have....or is it meant to be implemented with
other code to loop through these records...in other words am I meant to
use other code to loop through the records and this code just being the
latter half of it to pass the variables (fields) to the "SendMail"
function I have?

Kind Regards,

Liam

Jun 22 '06 #3

Li****@awamarin e.com.au wrote:
Thankyou so much for your reply....they are always extremely helpful!


Liam,

you might want to check out this link
http://groups.google.com/group/comp....dbc3a94dadba80

Lyle gives a good simple example of using CDOSys to send e-mails.

You could just set the .Body property of the message to the result of
the function, like this

Public Sub VerySimpleSendM ailWithCDOSampl e()
' requires reference to cdosys.dll
' (Microsoft CDO for Windows 2000 library)

Dim iCfg As CDO.Configurati on
Dim iMsg As CDO.Message

Set iCfg = New CDO.Configurati on
Set iMsg = New CDO.Message

With iCfg.Fields
..Item(cdoSendU singMethod) = cdoSendUsingPor t
..Item(cdoSMTPS erverPort) = 25
..Item(cdoSMTPS erver) = "smtp.mail.yaho o.ca"
..Item(cdoSMTPA uthenticate) = cdoBasic
..Item(cdoSendU serName) = "lylefair"
..Item(cdoSendP assword) = "Password"
..Item(cdoSendE mailAddress) = "Lyle Fairfield <lylef...@yahoo .ca>"
..Update
End With

With iMsg
..Configuration = iCfg
..Subject = "Test"
..To = "lylefairfi...@ aim.com"

'---.TextBody = "Test"
..TextBody = fMsgBody() '<=== stuff the result of fMsgBody into the
..Textbody property of the email.
..Send
End With
End Sub

Jun 22 '06 #4
thankyou for the reply.....this is very interesting, and I appreciate
your time!
Could you please explain how I am meant to pass "fMsgBody() " code you
wrote for me in previous post to my Command "SendMail" or the
CDOSys....from my Query Email...and to all the records within it?
pi********@hotm ail.com wrote:
Li****@awamarin e.com.au wrote:
Thankyou so much for your reply....they are always extremely helpful!


Liam,

you might want to check out this link
http://groups.google.com/group/comp....dbc3a94dadba80

Lyle gives a good simple example of using CDOSys to send e-mails.

You could just set the .Body property of the message to the result of
the function, like this

Public Sub VerySimpleSendM ailWithCDOSampl e()
' requires reference to cdosys.dll
' (Microsoft CDO for Windows 2000 library)

Dim iCfg As CDO.Configurati on
Dim iMsg As CDO.Message

Set iCfg = New CDO.Configurati on
Set iMsg = New CDO.Message

With iCfg.Fields
.Item(cdoSendUs ingMethod) = cdoSendUsingPor t
.Item(cdoSMTPSe rverPort) = 25
.Item(cdoSMTPSe rver) = "smtp.mail.yaho o.ca"
.Item(cdoSMTPAu thenticate) = cdoBasic
.Item(cdoSendUs erName) = "lylefair"
.Item(cdoSendPa ssword) = "Password"
.Item(cdoSendEm ailAddress) = "Lyle Fairfield <lylef...@yahoo .ca>"
.Update
End With

With iMsg
.Configuration = iCfg
.Subject = "Test"
.To = "lylefairfi...@ aim.com"

'---.TextBody = "Test"
.TextBody = fMsgBody() '<=== stuff the result of fMsgBody into the
.Textbody property of the email.
.Send
End With
End Sub


Jun 22 '06 #5
okay....I have created this so far:

Dim rst As Object
Set rst = Me.Recordset.Cl one
With rst
.MoveFirst
Do While Not .EOF
SendMail ("ga*********** *@hotmail.com")
rst.MoveNext
Loop

End With
End Sub

This Initiates my "SendMail" email code.....can you please help me add
the fields "IMO Number", "SBMA Number", "Date of Issue", "Due Date",
and "Vessel Name", from the record to pass into the "SendMail" email
code....and also the code for "SendMail", as the one I am currently
using is obviously not appropriate for my cause??????

Kind Regards

Liam
Li****@awamarin e.com.au wrote:
thankyou for the reply.....this is very interesting, and I appreciate
your time!
Could you please explain how I am meant to pass "fMsgBody() " code you
wrote for me in previous post to my Command "SendMail" or the
CDOSys....from my Query Email...and to all the records within it?
pi********@hotm ail.com wrote:
Li****@awamarin e.com.au wrote:
Thankyou so much for your reply....they are always extremely helpful!


Liam,

you might want to check out this link
http://groups.google.com/group/comp....dbc3a94dadba80

Lyle gives a good simple example of using CDOSys to send e-mails.

You could just set the .Body property of the message to the result of
the function, like this

Public Sub VerySimpleSendM ailWithCDOSampl e()
' requires reference to cdosys.dll
' (Microsoft CDO for Windows 2000 library)

Dim iCfg As CDO.Configurati on
Dim iMsg As CDO.Message

Set iCfg = New CDO.Configurati on
Set iMsg = New CDO.Message

With iCfg.Fields
.Item(cdoSendUs ingMethod) = cdoSendUsingPor t
.Item(cdoSMTPSe rverPort) = 25
.Item(cdoSMTPSe rver) = "smtp.mail.yaho o.ca"
.Item(cdoSMTPAu thenticate) = cdoBasic
.Item(cdoSendUs erName) = "lylefair"
.Item(cdoSendPa ssword) = "Password"
.Item(cdoSendEm ailAddress) = "Lyle Fairfield <lylef...@yahoo .ca>"
.Update
End With

With iMsg
.Configuration = iCfg
.Subject = "Test"
.To = "lylefairfi...@ aim.com"

'---.TextBody = "Test"
.TextBody = fMsgBody() '<=== stuff the result of fMsgBody into the
.Textbody property of the email.
.Send
End With
End Sub


Jun 22 '06 #6
Okay, how about the SQL for the query? Is this where the four fields
are coming from?

If so, your message body function is pretty simple... once you get this
working, you could make fMsgBody churn out a formatted table... but
that's later.

Function fMsgBody() As String
'"IMO Number", "SBMA Number", "Date of Issue", "Due Date",and "Vessel
Name"

dim rsDue as dao.recordset
dim strList as string '---place to dump all the names in the
query

set rsDue=DBEngine( 0)(0).OpenRecor dset("qryDueMai ls")
do until rsDue.EOF
strList=rsDue.F ields("IMO Number") & vbtab & _
rsDue.Fields("S BMA Number") & vbtab & _
rsDue.Fields("D ate of Issue") & vbtab & _
rsDue.Fields("D ue Date") & vbtab & _
rsDue.Fields("V essel Name") & vbcrlf
rsDue.MoveNext
loop

fMsgBody="The following accounts are due:" & vbcrlf & strList

rsDue.Close
set rsDue=Nothing

End Function

Then just use fMsgBody instead of your normal message text. It'll
build the message for you. Then you just assign the result of this
function to the .TEXT or .BODY property of the Message (in Lyle's
code).

Of course, if you don't understand some VB, this is very likely going
to blow right over your head.

I hope this helps

Pieter

Jun 22 '06 #7
I am doing something very similar in an access database and thought
this post was very helpful, but I am having some trouble.

I created the Function as a public function and then tried to call the
fMsgBody as the text part of my email and I recieved a compile error:
Expected array message. I can get the email portion to work if I don't
call the fMsgBody() function... so obviously my error is in the
fMsgBody portion.

I have :
Public Function fMsgBody() As String
Dim rsDue As DAO.Recordset
Dim strList As String '---place to dump all the names in the
Query

Set rsDue = DBEngine(0)(0). OpenRecordset("[Query]![Mail IACUC
Registrations]")
Do Until rsDue.EOF
strList = rsDue.Fields("P rotocol Number") & vbCrLf
rsDue.MoveNext
Loop

fMsgBody = "You have indicated this person will work on the
following protocols:" & vbCrLf & strList

rsDue.Close
Set rsDue = Nothing

End Function

'and the mail portion

Private Sub IACUC_CHANGE_Cl ick()
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Applica tion
Dim MyMail As Outlook.MailIte m
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObjec t
Dim MyBody As TextStream
Dim MyBodyText As String
Dim fMsgBody As String
Dim strList As String

Set fso = New FileSystemObjec t

' Now, we open Outlook for our own device..
Set MyOutlook = New Outlook.Applica tion

' Set up the database and query connections
Set db = CurrentDb()
' This creates the e-mail

Set MyMail = MyOutlook.Creat eItem(olMailIte m)

' This addresses it
MyMail.To = [Forms]![Personnel Form2]![Department Contact
Email]

'This gives it a subject
MyMail.Subject = "Current IACUC Approval of Change Form"

'This gives it the body
MyMail.Body = fMsgBody()
'MyMail.Body = "Dear Dr. " & [Forms]![Personnel
Form2]![Department Name] & vbCrLf & vbCrLf & "Attached is the Request
for IACUC Approval of Change to an Animal Care and Use Protocol
(amendment) form. Please fill one out for each of the currently
approved IACUC protocol(s) on which you have indicated you wish to add
" & [Forms]![Personnel Form2]![First Name] & [Forms]![Personnel
Form2]![Last Name] & ". Please edit the amendment form(s), complete
Section A and be sure to list relevant training and experience
information. Print a hard copy and return the original signed and
dated form(s) (including training and experience information) to me via
interoffice mail or in person. Please note: new personnel may NOT
participate on any IACUC protocol until approval from the IACUC is
received." & vbCrLf & vbCrLf & "Thank you for your attention to this
regulatory matter." & vbCrLf & vbCrLf & "Marsha Arnall" & vbCrLf &
"Research Regulations Specialist" & fMsgBody

'send an attachment

MyMail.Attachme nts.Add "X:\IACUC Administration\ IACUC Forms
for Researchers\090 4 Updated Amendment - Request for Change to Protocol
form.doc", olByValue, 1, "My Displayname"

So... can I use the acess query in the openrecordset? Or do I need to
write the query in vba (it is a pretty complicate sql statement) How
do I incorporate the sql into the vba?

Thanks,

Jessica

pi********@hotm ail.com wrote:
Okay, how about the SQL for the query? Is this where the four fields
are coming from?

If so, your message body function is pretty simple... once you get this
working, you could make fMsgBody churn out a formatted table... but
that's later.

Function fMsgBody() As String
'"IMO Number", "SBMA Number", "Date of Issue", "Due Date",and "Vessel
Name"

dim rsDue as dao.recordset
dim strList as string '---place to dump all the names in the
query

set rsDue=DBEngine( 0)(0).OpenRecor dset("qryDueMai ls")
do until rsDue.EOF
strList=rsDue.F ields("IMO Number") & vbtab & _
rsDue.Fields("S BMA Number") & vbtab & _
rsDue.Fields("D ate of Issue") & vbtab & _
rsDue.Fields("D ue Date") & vbtab & _
rsDue.Fields("V essel Name") & vbcrlf
rsDue.MoveNext
loop

fMsgBody="The following accounts are due:" & vbcrlf & strList

rsDue.Close
set rsDue=Nothing

End Function

Then just use fMsgBody instead of your normal message text. It'll
build the message for you. Then you just assign the result of this
function to the .TEXT or .BODY property of the Message (in Lyle's
code).

Of course, if you don't understand some VB, this is very likely going
to blow right over your head.

I hope this helps

Pieter
Jul 19 '06 #8
So what *exactly* are you trying to do? Never mind what Liam wrote.
Because the butchered code doesn't mean a whole lot. I know what the
original code did, but what are you trying to do? Just send a unique
e-mail to a list of addresses in a query?

Then you do something like

do until rsRecipients.EO F
with olkMsg
.Body="Hello " & rsRecipients.Fi elds("FirstName ")...
.Recipient = rsRecipients.Fi elds("EMailAddr ess")
.Subject = "Some Subject"
.Send
end with
rsRecipients.Mo veNext
loop

Jul 19 '06 #9
No, I am sending one email to a specific person listed on the open form
that includes a list of items relating to them.

I am trying to create a button that generates an email telling the
person to update forms for a list of protocols. It then attaches the
protocol amendment form. The email button works great... I can attach
the correct file, address it to the person listed on the form, add a
message. The only part I am having trouble with is incorporating the
list of protocols that need to be updated. I want to add this part
into the body of the message. (It is similar to the previous persons
example of sending a message about updating the following accounts)

Public Function fMsgBody() As String

Dim rsDue As DAO.Recordset
Dim strList As String '---place to dump all the names in the
Query

Set rsDue = DBEngine(0)(0). OpenRecordset(" SELECT [Current IACUC
Protocols].[Protocol Number], [Current IACUC Protocols].[Protocol
Name], [New Personnel].[Member ID]" & _
"FROM ([New Personnel] INNER JOIN [registrations list] ON [New
Personnel].[Member ID] = [registrations list].[Member ID]) INNER JOIN
[Current IACUC Protocols] ON [registrations list].[RegistrationFor m ID]
= [Current IACUC Protocols].[Protocol Number]" & _
"WHERE ((([New Personnel].[Member ID])=[Forms]![Personnel
Form2]![Member ID])) OR ((([New Personnel].[Member
ID])=[Forms]![Personnel Form2]![Member ID])) OR ((([New
Personnel].[Member ID])=[Forms]![Personnel Form2]![Member ID])) OR
((([New Personnel].[Member ID])=[Forms]![Personnel Form2]![Member ID]))
OR ((([New Personnel].[Member ID])=[Forms]![Personnel Form2]![Member
ID])) OR ((([New Personnel].[Member ID])=[Forms]![Personnel
Form2]![Member ID])) OR ((([New Personnel].[Member
ID])=[Forms]![Personnel Form2]![Member ID])) OR ((([New
Personnel].[Member ID])=[Forms]![Personnel Form2]![Member ID])) OR
((([New Personnel].[Member ID])=[Forms]![Personnel Form2]![Member
ID]))")

Do Until rsDue.EOF
strList = rsDue.Fields("P rotocol Number") & vbCrLf
rsDue.MoveNext
Loop
fMsgBody = "You have indicated this person will work on the
following protocols:" & vbCrLf & strList
rsDue.Close
Set rsDue = Nothing
End Function


pi********@hotm ail.com wrote:
So what *exactly* are you trying to do? Never mind what Liam wrote.
Because the butchered code doesn't mean a whole lot. I know what the
original code did, but what are you trying to do? Just send a unique
e-mail to a list of addresses in a query?

Then you do something like

do until rsRecipients.EO F
with olkMsg
.Body="Hello " & rsRecipients.Fi elds("FirstName ")...
.Recipient = rsRecipients.Fi elds("EMailAddr ess")
.Subject = "Some Subject"
.Send
end with
rsRecipients.Mo veNext
loop
Jul 20 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4605
by: Sameer | last post by:
I am supplying you with Sample Data:- Initial Classcode SampleSize Average ------- ---------- ------------------------------- ADK SSC 22 3.6800000000000002 ADK TSC 17 2.7599999999999998 ADK TSM 5 3.5499999999999998 ANB FCA 31 3.23 ANB FCB 50 3.0499999999999998 ANB FCC 30 3.0899999999999999
3
2062
by: brendan_gallagher_2001 | last post by:
Hi, I have a view(A) and I am trying to do a join on another table (B) to include only rows where date values in view A is greater than in table B. I also want the view to pick up rows in viewA based on date values. Here is what I have so far: SELECT * FROM viewA vw left JOIN tableB tb ON
10
15378
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have identical field names. The queries select a subset of the fields, so "Select *" is not really an option. Is there an easy way to change the source of a query, either in the design grid or SQL display? I suppose I could copy the SQL into WordPad...
14
2465
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 far with a loop in a form. Basically, I have key sums Current savings Current Salary Current deposit amount
2
3008
by: P B via AccessMonster.com | last post by:
I have a list of 160,000 records with these fields: fname, lname, address, city, state, zip, dob I need to generate a list with all fields where the first initial of lname and the dob are equal. How? I can't seem to get Left() to work in a query. Could I put this in a VBscript and generate a recordset? What's the easiest way to generate this list? This seems so simple.
3
8501
by: jwgoerlich | last post by:
Hello group, I am working on a query string class. The purpose is to parse name-value pairs from incoming text. Currently, I am using the Regex code below. I have two questions. First, the code below does not work if there is a space in the name. For example, the text "Initial Catalog=test;" parses to name=Catalog and value=test.
3
5579
by: tomlebold | last post by:
Look for query that changes Tom L LeBold into Tom LeBold and only when the middle intial exist.
35
9969
Curben
by: Curben | last post by:
Hello all, two days of websearching and I cannot find an answer yet. Reasonably new to access development. Access 2000 DB using access 2003 on windows XP I am having an issue with creating a query that I can enter the Part ID as value and hvae the description, cost etc. populate in the rest of the query. I have two Tables; ItemMaster and has one Value:
1
1698
by: jglabas | last post by:
For a report, I am using a query as my record source. The query produces 5 columns by 3272 records. The data in columns 1 & 2 (“Objective” and “Rating”) repeats every 409 records The data for “initial” and “Date” are unique for the individual. Currently there are 8 individuals (409 * 8 = 3272) . . . . .. . . . .Objective . . . Rating . . Initial . . . .. Date . . . . . Name . . . . .abc. . . . . . .a. . . . . . jg. . . . . .1/12/07 . ....
0
8823
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8237
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.