marcorangel
New Member
- Joined
- Jun 25, 2014
- Messages
- 1
Hello all,
I need your help in making this code work..
I should preface this by stating that I'm relatively new to VBA code so please don't get to technical on me....
This code utilized access tables to generage emails that get sent out, however, once it gets to the process called "run no survey distrcts" it gets stuck and it gives me a run-time error 429 saying that the ActiveX component can not create the object.
Here is the code:
Sub NonTopBoxReport()
Dim rs As DAO.Recordset
Dim olApp As Object
Dim objMail As Object
'Run non-top box district reports
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblDistrictsWithNonTopBox")
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
DoCmd.OpenReport "DailySummaryNTB", acViewPreview, , "TIER60_DIST_NM = '" & rs!TIER60_DIST_NM & "'"
DoCmd.OutputTo acOutputReport, "DailySummaryNTB", acFormatPDF, "C:\Users\u097951\Desktop\CE Daily Report\" & rs!District_Name & ".pdf", False
DoCmd.SendObject acSendReport, "DailySummaryNTB", acFormatPDF, rs!District_Manager_Email, "myemailaddress@me.com; " & rs!Market_President_Email & "; " & rs!All_MSC, , "CE Daily Summary - " & rs!District_Name, , False
DoCmd.Close acReport, "DailySummaryNTB"
rs.MoveNext
Loop
Else
End If
'Run all top box district reports
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblDistrictsWithAllTopBox")
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
DoCmd.OpenReport "DailySummaryATB", acViewPreview, , "TIER60_DIST_NM = '" & rs!TIER60_DIST_NM & "'"
DoCmd.OutputTo acOutputReport, "DailySummaryATB", acFormatPDF, "C:\Users\u097951\Desktop\CE Daily Report\" & rs!District_Name & ".pdf", False
DoCmd.SendObject acSendReport, "DailySummaryATB", acFormatPDF, rs!District_Manager_Email, "myemailaddress@me.com; " & rs!Market_President_Email & "; " & rs!All_MSC, , "CE Daily Summary - " & rs!District_Name, , False
DoCmd.Close acReport, "DailySummaryATB"
rs.MoveNext
Loop
Else
End If
'Run no survey districs process
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblDistrictsWithNoSurveys")
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
Set olApp = GetObject(, "Outlook.Application")
Set objMail = olApp.createitem(olMailItem)
With objMail
.BodyFormat = olFormatHTML
.To = rs!District_Manager_Email
.CC = "myemailaddress@me.com; " & rs!Market_President_Email & "; " & rs!All_MSC
.Subject = "CE Daily Summary - " & rs!District_Name & " (No Surveys)"
.HTMLBody = "No surveys to report."
.Send
End With
rs.MoveNext
Loop
Else
End If
With DoCmd
.SetWarnings False
.OpenQuery "qryLastProcessedSurveyDate"
.SetWarnings True
End With
rs.Close
DoCmd.Quit
End Sub
I need your help in making this code work..
I should preface this by stating that I'm relatively new to VBA code so please don't get to technical on me....
This code utilized access tables to generage emails that get sent out, however, once it gets to the process called "run no survey distrcts" it gets stuck and it gives me a run-time error 429 saying that the ActiveX component can not create the object.
Here is the code:
Sub NonTopBoxReport()
Dim rs As DAO.Recordset
Dim olApp As Object
Dim objMail As Object
'Run non-top box district reports
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblDistrictsWithNonTopBox")
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
DoCmd.OpenReport "DailySummaryNTB", acViewPreview, , "TIER60_DIST_NM = '" & rs!TIER60_DIST_NM & "'"
DoCmd.OutputTo acOutputReport, "DailySummaryNTB", acFormatPDF, "C:\Users\u097951\Desktop\CE Daily Report\" & rs!District_Name & ".pdf", False
DoCmd.SendObject acSendReport, "DailySummaryNTB", acFormatPDF, rs!District_Manager_Email, "myemailaddress@me.com; " & rs!Market_President_Email & "; " & rs!All_MSC, , "CE Daily Summary - " & rs!District_Name, , False
DoCmd.Close acReport, "DailySummaryNTB"
rs.MoveNext
Loop
Else
End If
'Run all top box district reports
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblDistrictsWithAllTopBox")
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
DoCmd.OpenReport "DailySummaryATB", acViewPreview, , "TIER60_DIST_NM = '" & rs!TIER60_DIST_NM & "'"
DoCmd.OutputTo acOutputReport, "DailySummaryATB", acFormatPDF, "C:\Users\u097951\Desktop\CE Daily Report\" & rs!District_Name & ".pdf", False
DoCmd.SendObject acSendReport, "DailySummaryATB", acFormatPDF, rs!District_Manager_Email, "myemailaddress@me.com; " & rs!Market_President_Email & "; " & rs!All_MSC, , "CE Daily Summary - " & rs!District_Name, , False
DoCmd.Close acReport, "DailySummaryATB"
rs.MoveNext
Loop
Else
End If
'Run no survey districs process
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblDistrictsWithNoSurveys")
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
Set olApp = GetObject(, "Outlook.Application")
Set objMail = olApp.createitem(olMailItem)
With objMail
.BodyFormat = olFormatHTML
.To = rs!District_Manager_Email
.CC = "myemailaddress@me.com; " & rs!Market_President_Email & "; " & rs!All_MSC
.Subject = "CE Daily Summary - " & rs!District_Name & " (No Surveys)"
.HTMLBody = "No surveys to report."
.Send
End With
rs.MoveNext
Loop
Else
End If
With DoCmd
.SetWarnings False
.OpenQuery "qryLastProcessedSurveyDate"
.SetWarnings True
End With
rs.Close
DoCmd.Quit
End Sub