源代码如下:
'------------------------------------------------------------
' sendmail
'------------------------------------------------------------
function sendmail(id as integer, username as string, emailaddr as string)
on error goto sendmail_err
'dim id as integer
dim cont as string 'condition for open report
dim subject as string
cont = "[id]=" & id
subject = username & ",please find attached your pay slip for " & month(now())
docmd.setwarnings false
docmd.openreport "report_2003", acpreview, "", cont
docmd.sendobject acreport, "report_2003", "snapshotformat(*.snp)", emailaddr, "", "", subject, "", false, ""
docmd.close acreport, "report_2003"
send 按钮单击事件代码
private sub send_click()
on error goto err_send_click
dim db1 as dao.database
dim user as dao.recordset
set db1 = application.currentdb
set user = db1.openrecordset("transfer", dbopentable)
dim failuser as string
failuser = "there some user's email is empty! "
with user
do while not user.eof
if isnull(![e-mail address]) then
failuser = failuser & " " & ![employee name]
else
sendmail ![id], ![employee name], ![e-mail address]
end if
.movenext
loop
end with
msgbox failuser
exit_send_click:
exit sub
err_send_click:
msgbox err.description
resume exit_send_click
end sub