Hey guys,
If anyone could spare sometime to help me out, it would be very much
appreciated.... .what I am trying to do is automate a "Command" that
sends me an Email. I have created a Query that grabs all the records I
am after...now all I need to do is get some code that will allow me
loop through each of these records shown by the query and pass certain
fields from these records into the Body of my email command...which
then emails itself to one person, and that person being myself.
The Email command I have at the moment, is as follows:
Sub SendMail(strTo)
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String
Dim olApp As Outlook.Applica tion
Dim olNs As Outlook.NameSpa ce
Dim olMail As Outlook.MailIte m
strsubject = "ATTN:Shore-Based Maintainance Agreements"
varbody = fMsgBody
Set olApp = CreateObject("O utlook.Applicat ion")
Set olNs = olApp.GetNamesp ace("MAPI")
olNs.Logon
Set olMail = olApp.CreateIte m(olMailItem)
olMail.To = strTo
olMail.Subject = strsubject
olMail.Body = fMsgBody
olMail.Send
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
End Sub
I just need some code to automate the above with the fields from the
records passed into the Body of the email....so far I have this......
Private Sub SBMACheckAndEma il_Click()
Dim rst As DAO.Recordset
Dim strList As String
Set rst = DBEngine(0)(0). OpenRecordset(" qryEmail")
Do Until rst.EOF
strList = rst.Fields("SMB A Number") & " " & rst.Fields("Ves sel
Name") & "" & rst.Fields("IMO Number") & "" & rst.Fields("Dat e of
Issue") & vbCrLf
SendMail ("ga*********** *@hotmail.com")
rst.MoveNext
Loop
fMsgBody = "The following accounts are due:" & vbCrLf & strList
rst.Close
Set rst = Nothing
End Function
End Sub
If someone could point me in the right direction it would be very much
appreciated
Kind Regards 11 1928
> I just need some code to automate the above with the fields from the records passed into the Body of the email....so far I have this......
Private Sub SBMACheckAndEma il_Click()
Dim rst As DAO.Recordset Dim strList As String
Set rst = DBEngine(0)(0). OpenRecordset(" qryEmail") Do Until rst.EOF strList = rst.Fields("SMB A Number") & " " & rst.Fields("Ves sel Name") & "" & rst.Fields("IMO Number") & "" & rst.Fields("Dat e of Issue") & vbCrLf SendMail ("ga*********** *@hotmail.com") rst.MoveNext Loop
fMsgBody = "The following accounts are due:" & vbCrLf & strList
rst.Close Set rst = Nothing
End Function End Sub
If someone could point me in the right direction it would be very much appreciated
Kind Regards
WOW. You're confused. I thought you wanted to send the entire query
result to yourself in a single e-mail. What you're doing now is
sending an e-mail per record. If not, you have to put the .SendMail
call OUTSIDE your loop. You might want to get a beginner book on VBA.
Perhaps that will sort you out a little. From the look of your code,
you don't really understand what's going on at all. And as it says in
the 10 commandments...
Thou shalt not copy and paste other people's code without at least
attempting to understand what it does.
You might be better off thinking this through on paper and writing down
exactly what you want to achieve. Then you can figure out the basic
steps and then solve those problems one at a time. I'm not saying this
to be critical, but because your code shows that you seem not to
understand what's going on in the code. And without that, you won't
learn a thing. Sorry to be rough, but that's the way I see it.
Here's a starter list:
1. create the message body by collapsing the query result into either
an HTML table or something I can stuff into the Message Body.
2. prepend the field names in the query (if necessary)
3. write some code to send the e-mail.
You don't need a form at all to do this. You can open the recordset in
a code module and process from there. Then call it when the DB opens
or something...
hahahaha so harsh, but so true! I definately agree with you...I am
getting rather confused, but please also understand this fact, I am
more than competent in areas such as Web Design and HTML/ CSS, but when
it comes to V.B I definately lack the experience and knowledge....an d
hence why I seek the assistance of professionals such as yourself, who
always have been extremely helpful. The assistance that I have been
provided by yourself and others through these forum's has been
priceless, and it is EXTREMELY well appreciated! I do however, have a
rough idea about certain elements of the code and what it is doing, and
have therefore been able to essentially "wing" alot/ all of my database
construction, as I'm essentially unable to write code myself...yet I
can adopt/interpret/manipulate most of the code (so far..and up until
now)....for my purpose and intent!?
I can assure you though, however, that once I have finally figured out
this last little piece of the puzzle...my database shall be complete,
and it will definately be my last database attempt...I WILL be retiring
indefinately hahaha! I have learnt many valuable lessons and it has
been challenging to say the least BUT there will be NO MORE :-p
Soooooooooo if you could please just bare with me and help get me
through this last step, then its game over, and what a games its been!
Now you are correct...I dont neccessarily want to have each record
emailed individually... but perhaps the whole table...how would I go
about this....
Under the suggestion and help of Mr.Ken Sheridan...my email code has
been modified to this:
Sub SendMail(strTo As String, strList As String)
Dim strsubject As String
Dim strBody As String
Dim strattachment1 As String
Dim strattachment2 As String
Dim olApp As Outlook.Applica tion
Dim olNs As Outlook.NameSpa ce
Dim olMail As Outlook.MailIte m
strsubject = "ATTN:Shore-Based Maintainance Agreements"
strBody = "The following accounts are due:" & vbCrLf & strList
Set olApp = CreateObject("O utlook.Applicat ion")
Set olNs = olApp.GetNamesp ace("MAPI")
olNs.Logon
Set olMail = olApp.CreateIte m(olMailItem)
olMail.To = strTo
olMail.Subject = strsubject
olMail.Body = strBody
olMail.Send
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
End Sub
To be called by: SendMail ("gatecrasher.. .@hotmail.com", strList)
And the values to be placed in the email:
strList = _
rst.Fields("Ves sel Name") & " " & _
rst.Fields("IMO Number") & " " & _
rst.Fields("Due Date")& " " &_
rst.Fields("Dat e of Issue") & vbCrLf
The Question is how am I meant to incorporate all of this for my intent
and purpose...as previously explained to you?
Tks/ Brgds
Liam.
> Sub SendMail(strTo As String, strList As String)
Dim strsubject As String Dim strBody As String Dim strattachment1 As String Dim strattachment2 As String Dim olApp As Outlook.Applica tion Dim olNs As Outlook.NameSpa ce Dim olMail As Outlook.MailIte m
strsubject = "ATTN:Shore-Based Maintainance Agreements" strBody = "The following accounts are due:" & vbCrLf & strList
HUH? where does the value of strList come from? No call like
strList=fMessag eBody()
???
What follows will only return ONE record, at most. You need to loop
through ALL of them.
strList = _ rst.Fields("Ves sel Name") & " " & _ rst.Fields("IMO Number") & " " & _ rst.Fields("Due Date")& " " &_ rst.Fields("Dat e of Issue") & vbCrLf
I already showed you how to do this. You create a FUNCTION to return
the list of values. Then you assign that result to the .Body property
of your e-mail.
As David said, I already answered your question. The fact that the
answer blew right over your head is not my fault. My original answer,
which I stand by, was:
1. create a function to return the list of records as a single string.
2. create a function to send the e-mail (so I sent you to Danny's
website)
3. create a routine/scheduler to send the e-mails.
The fact that you don't know how to use the NG's effectively is your
own fault. Maybe you should learn to search them. Surely the answer
is there somewhere. you just have to put the pieces together. If you
really want to make this happen without any learning or knowledge on
your part, please insert money.
Thanks,
Pieter
FUNCTION fMsgBody()
Dim rst As DAO.Recordset
Dim strList As String
Set rst = DBEngine(0)(0). OpenRecordset(" qryEmail")
Do Until rst.EOF
strList = rst.Fields("SMB A Number") & " " & rst.Fields("Ves sel
Name") & "" & rst.Fields("IMO Number") & "" & rst.Fields("Dat e of
Issue") & vbCrLf
rst.MoveNext
Loop
fMsgBody = "The following accounts are due:" & vbCrLf & strList
rst.Close
Set rst = Nothing
End Function
you call this function INSIDE your e-mailing routine. or just set the
..BODY property of the e-mail to the result of the function, e.g.,
olkMsg.Body = fMsgBody()
If this confuses you that much, you should probably pay someone to sort
it out for ya. At this rate, it'll never get done. You seem to be
moving backwards instead of forwards. Li****@awamarin e.com.au wrote: hahahaha so harsh, but so true! I definately agree with you...I am getting rather confused, but please also understand this fact, I am more than competent in areas such as Web Design and HTML/ CSS, but when it comes to V.B I definately lack the experience and knowledge....an d hence why I seek the assistance of professionals such as yourself, who always have been extremely helpful. The assistance that I have been provided by yourself and others through these forum's has been priceless, and it is EXTREMELY well appreciated! I do however, have a rough idea about certain elements of the code and what it is doing, and have therefore been able to essentially "wing" alot/ all of my database construction, as I'm essentially unable to write code myself...yet I can adopt/interpret/manipulate most of the code (so far..and up until now)....for my purpose and intent!?
Have you considered offering to endorse Access in Microsoft
commercials? I think you are the perfect example of the user for whom
MS has created Access 2007.
hahahaha thanks lyle...I am Business (Marketing) graduate...so yes I
can talk the talk...Regards Liam
Lyle Fairfield wrote: Li****@awamarin e.com.au wrote:
hahahaha so harsh, but so true! I definately agree with you...I am getting rather confused, but please also understand this fact, I am more than competent in areas such as Web Design and HTML/ CSS, but when it comes to V.B I definately lack the experience and knowledge....an d hence why I seek the assistance of professionals such as yourself, who always have been extremely helpful. The assistance that I have been provided by yourself and others through these forum's has been priceless, and it is EXTREMELY well appreciated! I do however, have a rough idea about certain elements of the code and what it is doing, and have therefore been able to essentially "wing" alot/ all of my database construction, as I'm essentially unable to write code myself...yet I can adopt/interpret/manipulate most of the code (so far..and up until now)....for my purpose and intent!?
Have you considered offering to endorse Access in Microsoft commercials? I think you are the perfect example of the user for whom MS has created Access 2007.
okay...created function....sho wn:
Private Function fMsgBody()
Dim rst As DAO.Recordset
Dim strList As String
Set rsDue = DBEngine(0)(0). OpenRecordset(" qryEmail")
Do Until rsDue.EOF
SendMail ("ga*********** *@hotmail.com")
strList = rsDue.Fields("I MO 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
Dim strsubject As String
Dim strBody As String
Dim strattachment1 As String
Dim strattachment2 As String
Dim olApp As Outlook.Applica tion
Dim olNs As Outlook.NameSpa ce
Dim olMail As Outlook.MailIte m
strsubject = "ATTN:Shore-Based Maintainance Agreements"
strBody = "The following accounts are due:" & vbCrLf & strList =
fMessageBody()
Set olApp = CreateObject("O utlook.Applicat ion")
Set olNs = olApp.GetNamesp ace("MAPI")
olNs.Logon
Set olMail = olApp.CreateIte m(olMailItem)
olMail.To = strTo
olMail.Subject = strsubject
olMail.Body = strBody
olMail.SendMail
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
End Function
yet still doesnt work?
Suggestion? pi********@hotm ail.com wrote: FUNCTION fMsgBody() Dim rst As DAO.Recordset Dim strList As String
Set rst = DBEngine(0)(0). OpenRecordset(" qryEmail") Do Until rst.EOF strList = rst.Fields("SMB A Number") & " " & rst.Fields("Ves sel
Name") & "" & rst.Fields("IMO Number") & "" & rst.Fields("Dat e of Issue") & vbCrLf
rst.MoveNext Loop
fMsgBody = "The following accounts are due:" & vbCrLf & strList
rst.Close Set rst = Nothing
End Function
you call this function INSIDE your e-mailing routine. or just set the .BODY property of the e-mail to the result of the function, e.g.,
olkMsg.Body = fMsgBody()
If this confuses you that much, you should probably pay someone to sort it out for ya. At this rate, it'll never get done. You seem to be moving backwards instead of forwards.
pasted wrong section:
Private Function fMsgBody()
Dim rst As DAO.Recordset
Dim strList As String
Set rst = DBEngine(0)(0). OpenRecordset(" qryEmail")
Do Until rst.EOF
strList = rst.Fields("IMO Number") & vbTab & _
rst.Fields("SBM A Number") & vbTab & _
rst.Fields("Dat e of Issue") & vbTab & _
rst.Fields("Due Date") & vbTab & _
rst.Fields("Ves sel Name") & vbCrLf
rst.MoveNext
Loop
fMsgBody = "The following accounts are due:" & vbCrLf & strList
rst.Close
Set rst = Nothing
End Function
Dim strsubject As String
Dim strBody As String
Dim strattachment1 As String
Dim strattachment2 As String
Dim olApp As Outlook.Applica tion
Dim olNs As Outlook.NameSpa ce
Dim olMail As Outlook.MailIte m
strsubject = "ATTN:Shore-Based Maintainance Agreements"
strBody = "The following accounts are due:" & vbCrLf & strList =
fMsgBody()
Set olApp = CreateObject("O utlook.Applicat ion")
Set olNs = olApp.GetNamesp ace("MAPI")
olNs.Logon
Set olMail = olApp.CreateIte m(olMailItem)
olMail.To = strTo
olMail.Subject = strsubject
olMail.Body = fMsgBody()
olMail.SendMail ("ga*********** *@hotmail.com")
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
End Function
pasted wrong section:
Private Function fMsgBody()
Dim rst As DAO.Recordset
Dim strList As String
Set rst = DBEngine(0)(0). OpenRecordset(" qryEmail")
Do Until rst.EOF
strList = rst.Fields("IMO Number") & vbTab & _
rst.Fields("SBM A Number") & vbTab & _
rst.Fields("Dat e of Issue") & vbTab & _
rst.Fields("Due Date") & vbTab & _
rst.Fields("Ves sel Name") & vbCrLf
rst.MoveNext
Loop
fMsgBody = "The following accounts are due:" & vbCrLf & strList
rst.Close
Set rst = Nothing
End Function
Dim strsubject As String
Dim strBody As String
Dim strattachment1 As String
Dim strattachment2 As String
Dim olApp As Outlook.Applica tion
Dim olNs As Outlook.NameSpa ce
Dim olMail As Outlook.MailIte m
strsubject = "ATTN:Shore-Based Maintainance Agreements"
strBody = "The following accounts are due:" & vbCrLf & strList =
fMsgBody()
Set olApp = CreateObject("O utlook.Applicat ion")
Set olNs = olApp.GetNamesp ace("MAPI")
olNs.Logon
Set olMail = olApp.CreateIte m(olMailItem)
olMail.To = strTo
olMail.Subject = strsubject
olMail.Body = fMsgBody()
olMail.SendMail ("ga*********** *@hotmail.com")
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
End Function This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nazgul |
last post by:
Hi!
I want to implement a small tool in Python for distributing "patches" and I
need Your advice. This application should be able to package all files
chosen by a user into a self-extracting.exe so that when you click on it, it
will extract the files and run setup.exe which among the other will copy
these files into respective folders (the absolute paths could be written in
some config file). Of course the files should be extracted first...
|
by: Avi |
last post by:
hi,
Can anyone tell me what the problem is and how to solve it
The following piece of code resides on an asp page on the server and
is used to download files from the server to the machine accessing the
abobe mentioned asp page. It WORKS for every type of file when I
change the content type according to the file type, but it won't work
with self extracting files. When an end user downloads a self
extracting file by accessing the...
|
by: Stanley Cheung |
last post by:
Hi all,
I am developing the application for send emailing list,
actually, i can perform to send a email 1 by 1 and do it on aspx page.
I have a enquiry that how can the application change to background task
instead of user need to wait and wait until all email sent.
Also, when user waiting to complete the emailing list, the page is blank and
nothing, can we put a layout when user waiting a request.
|
by: tafs7 |
last post by:
My code below is supposed to email me when an error occurs on the
application, but it's not emailing anything. Am I missing something?
I know the smtp servers I've tried work. I even added a App_Start
handler to see if I could get emailed at all even from the first
request of the app, but to no avail. Could someone please help me
out? Thanks a lot!
--Thiago
Web developer
AgniTEK
|
by: Mike Moore |
last post by:
What is the best way to launch outlook from an asp.net web page? Can you do this using MAPI or is there a control that you can purchase? We are unable to use SMTP. We use MS Exhange and MAPI currently for our client/server apps.
| |
by: Tim Hunter |
last post by:
I have two questions regarding emailing from Access.
My first question relates to how many email addresses is too much. I
have a client who wants to email 1500 people at once. Is this possible
or smart? what would be a reasonable number?
My second question is related to emailing customers who have an
anniversary or a Birthday. Is it possible to personalize each email with
a name?
TIA
Tim
|
by: kaferro |
last post by:
What is the typical way to loop through a vector while deleting
certain elements during the loop process? The code below works, but I
am wondering if there is a better solution.
vector<intvTmp;
vTmp.push_back(1);
vTmp.push_back(2);
vTmp.push_back(1);
vTmp.push_back(2);
|
by: Werner |
last post by:
Hi,
I try to read (and extract) some "self extracting" zipefiles on a
Windows system. The standard module zipefile seems not to be able to
handle this.
False
Is there a wrapper or has some one experience with other libaries to
|
by: paul814 |
last post by:
I've been working on this for some time now and have gotten
nowhere...hoping someone here can help.
I want to take and email all records in a database for the current
date when this php page is run.
Now I have a number of tables in this database...looking like this:
editorial
editorialdate, editorialname, editorialcomments
press
|
by: Lorenzo Villari |
last post by:
In
http://fms.komkon.org/EMUL8/HOWTO.html
I read:
"After initial values are assigned, we start the main loop:
for(;;)
{
|
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,...
| |
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| | |