Ringhal
07-07-2016, 05:29 AM
Hi all,
I have a problem with my code and I can’t seem to find the cause of it. I have code that loops through the customers sending a statement (report) to each customer. The code is perfect in that it sends the report to the customer as intended, but at the end of running, it causes all my menu buttons to not work. Closing the entire database fixes the menus. Disabling the send method (.Send) doesn’t cause this issue with my menu, but obviously this isn’t ideal.
Below is certain relevant section of my code.
Dim cdoMessage As CDO.Message
Dim cdoConfig As CDO.Configuration
Set cdoConfig = CreateObject("CDO.Configuration") 'Assign Config object
'these details are correct and confindetial
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" 'smtp address
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "" 'smtp port number
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = "" 'clear text authentication
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = "" 'smtp over the network
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = "" 'Use SSL
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 'timeout in seconds
'following settings are optional
.Item("http://schemas.microsoft.com/cdo/configuration/smtpaccountname") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress") = ""
'warning: it’s a security risk to hard-code your username and password
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
.Update
End With
'A temporary table is created that filters only the customers we're emailing
CountCustomers = Dcount("Customers", "MyTable") 'Count customers we're emailing to
for i =1 to CountCustomers
If cdoMessage Is Nothing Then Set cdoMessage = CreateObject("CDO.Message") 'Assign Message object
'Code to determine customer name and email address
'Code edits record source of the report to show only the customer name
'Report is saved in a folder on the drive
DoCmd.OutputTo acOutputReport, sExistingReportName, _
acFormatPDF, myReportOutput, , , , acExportQualityPrint
With cdoMessage
Set .Configuration = cdoConfig
.Subject = ""
.FROM = ""
.To = ""
.TextBody = ""
.AddAttachment myReportOutput 'Attachment path
.Send
Kill myReportOutput 'Deletes saved report
End With
next i
Set cdoConfig = Nothing 'Empty assigned object
Set cdoMessage = Nothing 'Empty assigned object
I have a problem with my code and I can’t seem to find the cause of it. I have code that loops through the customers sending a statement (report) to each customer. The code is perfect in that it sends the report to the customer as intended, but at the end of running, it causes all my menu buttons to not work. Closing the entire database fixes the menus. Disabling the send method (.Send) doesn’t cause this issue with my menu, but obviously this isn’t ideal.
Below is certain relevant section of my code.
Dim cdoMessage As CDO.Message
Dim cdoConfig As CDO.Configuration
Set cdoConfig = CreateObject("CDO.Configuration") 'Assign Config object
'these details are correct and confindetial
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" 'smtp address
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "" 'smtp port number
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = "" 'clear text authentication
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = "" 'smtp over the network
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = "" 'Use SSL
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 'timeout in seconds
'following settings are optional
.Item("http://schemas.microsoft.com/cdo/configuration/smtpaccountname") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress") = ""
'warning: it’s a security risk to hard-code your username and password
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
.Update
End With
'A temporary table is created that filters only the customers we're emailing
CountCustomers = Dcount("Customers", "MyTable") 'Count customers we're emailing to
for i =1 to CountCustomers
If cdoMessage Is Nothing Then Set cdoMessage = CreateObject("CDO.Message") 'Assign Message object
'Code to determine customer name and email address
'Code edits record source of the report to show only the customer name
'Report is saved in a folder on the drive
DoCmd.OutputTo acOutputReport, sExistingReportName, _
acFormatPDF, myReportOutput, , , , acExportQualityPrint
With cdoMessage
Set .Configuration = cdoConfig
.Subject = ""
.FROM = ""
.To = ""
.TextBody = ""
.AddAttachment myReportOutput 'Attachment path
.Send
Kill myReportOutput 'Deletes saved report
End With
next i
Set cdoConfig = Nothing 'Empty assigned object
Set cdoMessage = Nothing 'Empty assigned object