Nancythomas
Registered User.
- Local time
- Yesterday, 22:43
- Joined
- Apr 20, 2010
- Messages
- 59
How to email report & all documents from the (attachment table) for a given record
Hi
I have a VB Script. I can email a report for selected record to the email distribution list. I would need some help to also email all relevant attachments linked to the record.
I cannot get both to happen at the same time. Please help.
' Add attachments For x = LBound(varPaths) To UBound(varPaths)
.Attachments.Add varPaths(x)
The above does not work. Where can I insert the above VB Script to the below VB Script........
This VB Script works, but it only email the report and not attachments.....
Private Sub Email_AVLOG_Report_Click()
Dim oLook As Object
Dim oMail As Object
Dim olns As Outlook.NameSpace
Dim strTO As String
Dim strMessageBody As String
Dim strSubject As String
Dim myDB As DAO.Database
Dim rst As DAO.Recordset
'Do you even have E-Mail Addressess in the Mailing List Table?
'[EMailAddress] cannot be NULL
If DCount("[EMailAddress]", "MailingList_Tbl") = 0 Then Exit Sub
'' Exit Sub
Set myDB = CurrentDb
Set rst = myDB.OpenRecordset("MailingList_Tbl", dbOpenSnapshot, dbOpenForwardOnly)
Set oLook = CreateObject("Outlook.Application")
Set olns = oLook.GetNamespace("MAPI")
Set oMail = oLook.CreateItem(0)
'Build the Recipient List
With rst
Do While Not .EOF
strTO = strTO & ![EmailAddress] & ";"
.MoveNext
Loop
End With
'Remove Trailing ';'
strTO = Left$(strTO, Len(strTO) - 1)
'******************************* USER DEFINED SECTION ********************************
strMessageBody = "Reporting Av Log - Responsible Station :" & vbCrLf & vbCrLf & _
Forms!AVLOG_Frm.Station & vbCrLf & vbCrLf & _
"Forwarded for your information" & vbCrLf & vbCrLf & _
"Regards"
strSubject = "Av Log No: " & Forms!AVLOG_Frm.AVLOGID & " / Date: " & Forms!AVLOG_Frm.Date
oMail.Display
'*************************************************************************************
On Error Resume Next
DoCmd.SendObject acSendReport, "R1-AVLOG", acFormatPDF, strTO, , , strSubject, strMessageBody, True
DoCmd.SetWarnings (True)
MsgBox "Availability Log Message Sent Successfully!", vbOKOnly, "Mail Sent"
Set oMail = Nothing
Set oLook = Nothing
rst.Close
Set rst = Nothing
Hi
I have a VB Script. I can email a report for selected record to the email distribution list. I would need some help to also email all relevant attachments linked to the record.
I cannot get both to happen at the same time. Please help.
' Add attachments For x = LBound(varPaths) To UBound(varPaths)
.Attachments.Add varPaths(x)
The above does not work. Where can I insert the above VB Script to the below VB Script........
This VB Script works, but it only email the report and not attachments.....
Private Sub Email_AVLOG_Report_Click()
Dim oLook As Object
Dim oMail As Object
Dim olns As Outlook.NameSpace
Dim strTO As String
Dim strMessageBody As String
Dim strSubject As String
Dim myDB As DAO.Database
Dim rst As DAO.Recordset
'Do you even have E-Mail Addressess in the Mailing List Table?
'[EMailAddress] cannot be NULL
If DCount("[EMailAddress]", "MailingList_Tbl") = 0 Then Exit Sub
'' Exit Sub
Set myDB = CurrentDb
Set rst = myDB.OpenRecordset("MailingList_Tbl", dbOpenSnapshot, dbOpenForwardOnly)
Set oLook = CreateObject("Outlook.Application")
Set olns = oLook.GetNamespace("MAPI")
Set oMail = oLook.CreateItem(0)
'Build the Recipient List
With rst
Do While Not .EOF
strTO = strTO & ![EmailAddress] & ";"
.MoveNext
Loop
End With
'Remove Trailing ';'
strTO = Left$(strTO, Len(strTO) - 1)
'******************************* USER DEFINED SECTION ********************************
strMessageBody = "Reporting Av Log - Responsible Station :" & vbCrLf & vbCrLf & _
Forms!AVLOG_Frm.Station & vbCrLf & vbCrLf & _
"Forwarded for your information" & vbCrLf & vbCrLf & _
"Regards"
strSubject = "Av Log No: " & Forms!AVLOG_Frm.AVLOGID & " / Date: " & Forms!AVLOG_Frm.Date
oMail.Display
'*************************************************************************************
On Error Resume Next
DoCmd.SendObject acSendReport, "R1-AVLOG", acFormatPDF, strTO, , , strSubject, strMessageBody, True
DoCmd.SetWarnings (True)
MsgBox "Availability Log Message Sent Successfully!", vbOKOnly, "Mail Sent"
Set oMail = Nothing
Set oLook = Nothing
rst.Close
Set rst = Nothing