循环,提取和发送电子邮件? [英] Looping, extracting and emailing?

查看:87
本文介绍了循环,提取和发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,

如果有人可以在某个时候帮助我,那将会非常感谢..... b $ b赞赏.....我想要做的是自动化命令那个

给我发了一封电子邮件。我已经创建了一个查询,它可以获取我之后的所有记录...现在我需要做的就是获取一些代码,这些代码将允许我

循环遍历每个这些记录显示在查询中,并将这些记录中的某些

字段传递到我的电子邮件命令的正文......然后

然后将电子邮件发送给一个人和那个人作为我自己。


我目前的电子邮件命令如下:


Sub SendMail(strTo)


Dim strsubject As String

Dim varbody As Variant

Dim strattachment1 As String

Dim strattachment2 As String

Dim olApp作为Outlook.Application

Dim olNs作为Outlook.NameSpace

Dim olMail作为Outlook.MailItem

strsubject =" ; ATTN:岸基维护协议

varbody = fMsgBody

设置olApp = CreateObject(" Outlook.Application")

设置olNs = olApp.GetNamespace(" MAPI")

olNs.Logon

设置olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo

olMail.Subject = strsubject

olMail.Body = fMsgBody

olMail.Send

Set olNs = Nothing

Set olMail = Nothing

设置olApp = Nothing

End Sub

我只需要一些代码来自动化上面的字段来自

记录传递到电子邮件的正文....到目前为止我有这个...


私人子SBMACheckAndEmail_Click()

Dim rst as DAO.Recordset

Dim strList As String


设置rst = DBEngine(0)(0).OpenRecordset(" qryEmail")

直到rst.EOF

strList = rst.Fields(" SMBA Number")& " " &安培; rst.Fields(Vessel

Name)& "" &安培; rst.Fields(IMO Number)& "" &安培; rst.Fields("

Issue的日期)& vbCrLf

SendMail(" ga ************ @ hotmail.com")

rst.MoveNext

循环

fMsgBody ="以下帐户到期: &安培; vbCrLf& strList

rst.Close

Set rst = Nothing

结束功能

End Sub


如果有人能指出我正确的方向,那将非常感谢

赞赏


亲切的问候

推荐答案

>我只需要一些代码来自动化上面的内容,将
> I just need some code to automate the above with the fields from the
字段中的字段传递到电子邮件的正文....到目前为止,我有这个......
<私有子SBMACheckAndEmail_Click()

Dim rst作为DAO.Recordset
Dim strList As String

设置rst = DBEngine(0)(0).OpenRecordset (" qryEmail")
直到rst.EOF
strList = rst.Fields(" SMBA Number")& " " &安培; rst.Fields(Vessel
Name)& "" &安培; rst.Fields(IMO Number)& "" &安培; rst.Fields(发行日期)& vbCrLf
SendMail(" ga ************ @ hotmail.com")
rst.MoveNext
循环

fMsgBody = 以下账户到期: &安培; vbCrLf& strList

rst.Close
设置rst = Nothing

结束功能
结束子

如果有人能指点我正确的方向非常感谢

亲切的问候
records passed into the Body of the email....so far I have this......

Private Sub SBMACheckAndEmail_Click()
Dim rst As DAO.Recordset
Dim strList As String

Set rst = DBEngine(0)(0).OpenRecordset("qryEmail")
Do Until rst.EOF
strList = rst.Fields("SMBA Number") & " " & rst.Fields("Vessel
Name") & "" & rst.Fields("IMO Number") & "" & rst.Fields("Date 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




哇。你很困惑。我以为你想通过一封电子邮件将整个查询

结果发送给自己。你现在正在做的是

每条记录发送一封电子邮件。如果没有,你必须把.SendMail

调用OUTSIDE你的循环。你可能想要获得一本关于VBA的初学者书。

也许这会让你有所帮助。从您的代码看,

你真的不明白发生了什么。正如它在

中所说的10条诫命......


你至少不要复制和粘贴其他人的代码

试图理解它的作用。


你可能会更好地通过纸上书写这一点并写下来

正是你想要实现的目标。然后你可以找出基本的

步骤,然后一次解决这些问题。我不是说这个很重要,但是因为你的代码显示你似乎没有理解代码中发生了什么。如果没有这个,你就不会知道b $ b了解一件事。抱歉粗暴,但这就是我看到它的方式。


这里是一个入门名单:

1.创建消息正文将查询结果折叠成一个HTML表格或者我可以填充到消息正文中的东西。

2.在查询中添加字段名称(如果需要)

3.写一些代码来发送电子邮件。


你根本不需要表格来做这件事。您可以在

中打开记录集代码模块并从那里进行处理。然后在数据库打开时调用它

或者什么...



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...


haha​​haha如此苛刻,但是如此真实!我肯定同意你的意见......我很尴尬,但是也请理解这个事实,我在网页设计和HTML等领域胜过b $ b / CSS,但是当它来到VB时我肯定缺乏经验和知识......而且

因此我寻求专业人士的帮助,比如你自己,谁

总是非常有用。我自己和其他人通过这些论坛提供的帮助已经是无价的,而且非常值得赞赏!但是,我对代码的某些元素及其正在做的事情有一个粗略的想法,因此,因此
基本上可以翼。很多/我所有的数据库

构建,因为我自己基本上无法自己编写代码......但是我可以采用/解释/操作大部分代码(到目前为止......直到
现在为
)....为了我的目的和意图!?


我可以向你保证,但是,一旦我终于想出了这个难题的最后一小部分......我的数据库应该是完整的,

它绝对是我最后一次尝试数据库......我将退休

无限哈哈哈!我已经学到了很多有价值的课程,而且它已经很难说,至少可以说没有更多:-p

Soooooooooo如果你可以请我裸露通过最后一步帮助我获得
,然后游戏结束,以及它的游戏是什么!


现在你是对的...我不需要想要每个记录单独发送电子邮件

...但也许整张桌子......我怎么去

这个......

根据Ken Sheridan先生的建议和帮助......我的电子邮件代码已经被修改为:
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作为Outlook.Application

Dim olNs作为Outlook.NameSpace

Dim olMail作为Outlook.MailItem

strsubject =ATTN:岸基维护协议

strBody ="以下帐户到期: &安培; vbCrLf& strList

设置olApp = CreateObject(" Outlook.Application")

设置olNs = olApp.GetNamespace(" MAPI")

olNs .Logon

设置olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo

olMail.Subject = strsubject

olMail.Body = strBody

olMail.Send

设置olNs = Nothing

设置olMail = Nothing

设置olApp = Nothing


End Sub


要通过以下方式调用:SendMail(gatecrasher ... @ hotmail.com, strList)


以及要放在电子邮件中的值:


strList = _

rst.Fields (船舶名称)& " " &安培; _

rst.Fields(" IMO Number")& " " &安培; _

rst.Fields(截止日期)& " " & _

rst.Fields(发行日期)& vbCrLf

问题是我如何将所有这些用于我的意图

和目的......如前所述:

Tks / Brgds


利亚姆。

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....and
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.Application
Dim olNs As Outlook.NameSpace
Dim olMail As Outlook.MailItem
strsubject = "ATTN:Shore-Based Maintainance Agreements"
strBody = "The following accounts are due:" & vbCrLf & strList
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon
Set olMail = olApp.CreateItem(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("Vessel Name") & " " & _
rst.Fields("IMO Number") & " " & _
rst.Fields("Due Date")& " " &_
rst.Fields("Date 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)
> 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作为Outlook.Application
Dim olNs作为Outlook.NameSpace
Dim olMail作为Outlook.MailItem

strsubject =" ATTN:Shore - 基本维持协议
strBody =以下账目到期: &安培; vbCrLf& strList


HUH? strList的值来自哪里?不打电话如

strList = fMessageBody()

???


以下内容最多只返回一条记录。你需要通过所有这些来循环



strList = _
rst.Fields(" Vessel Name")& " " &安培; _
rst.Fields(" IMO Number")& " " &安培; _
rst.Fields(截止日期)& " " & _
rst.Fields(发行日期)& vbCrLf


Dim strsubject As String
Dim strBody As String
Dim strattachment1 As String
Dim strattachment2 As String
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olMail As Outlook.MailItem
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=fMessageBody()
???

What follows will only return ONE record, at most. You need to loop
through ALL of them.
strList = _
rst.Fields("Vessel Name") & " " & _
rst.Fields("IMO Number") & " " & _
rst.Fields("Due Date")& " " &_
rst.Fields("Date of Issue") & vbCrLf




我已经告诉你如何做到这一点。您创建一个FUNCTION以返回

值列表。然后你将结果分配给.Body属性

你的电子邮件。


正如大卫所说,我已经回答了你的问题。

答案在你头上爆炸的事实不是我的错。我原来的答案,我支持的
是:


1.创建一个函数,将记录列表作为单个字符串返回。

2.创建一个发送电子邮件的功能(所以我把你送到了Danny的

网站)

3.创建一个例程/调度程序发送电子邮件。


事实上你不知道如何有效地使用NG'是你自己的错误。也许你应该学会搜索它们。肯定是答案

在某处。你只需把各个部分放在一起。如果你想要在没有任何学习或知识的情况下实现这一点,请插入资金。


谢谢,


Pieter



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


这篇关于循环,提取和发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆