Cannot Complete Action Whilst Processing (1 Viewer)

abbaddon223

Registered User.
Local time
Today, 08:36
Joined
Mar 13, 2010
Messages
162
Hi,

I'm trying to setup a process of opening a form, saving to a location, emailing it as a PDF, killing the PDF, move onto the next form - rinse wash repeat until done.

The below works fine on a single click, however if I try to set it as an event timer of loop, I get an error saying: This action cannot be carried out whilst processing a form or report event.

Any help really appreciated!!!!! :banghead:



Do

Dim outputFileName, Ref As String
Ref = Vici_URN
outputFileName = CurrentProject.Path & "\Claim Packages\CICA\" & Ref & " - " & Format(Date, "yyyyMMdd") & ".pdf"


DoCmd.OutputTo acOutputForm, "Frm_CICA_Bulk_Send", acFormatPDF, outputFileName


Dim Attach As String
Attach = outputFileName

Dim iCfg As Object
Dim iMsg As Object

Set iCfg = CreateObject("CDO.Configuration")
Set iMsg = CreateObject("CDO.Message")

With iCfg.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") =
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") =
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") =
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") =
.Update
End With

With iMsg
.Configuration = iCfg
.Subject = "Hotkey Transfer From"
.To =
.CC = ""
.BCC = "phil.little@.co.uk"
.TextBody = "Please find the enclosed customer details for Hotkey Transfer"
.AddAttachment Attach
.Send
End With

Set iMsg = Nothing
Set iCfg = Nothing


Kill outputFileName
[CurrentState] = "Sent"
DateSent = Date
TimeSent = Time()
DoCmd.GoToRecord acDataForm, "Frm_CICA_Bulk_Send", acNext

Loop
 

Foe

Registered User.
Local time
Today, 09:36
Joined
Aug 28, 2013
Messages
80
Not sure I'm following exactly since I haven't dealt with emailing via code, but I've faced a similar issue before. Mine was trying to save a PDF of a report as it closes.

What I did to deal with it:
Create an identical report.
When the original report is closing, it opens the other report (acHidden) with identical parameters. It then creates the PDF, closes the copy and finishes closing itself.

snippet from the Report_Close event:
Code:
DoCmd.OpenReport "rptDailyLog", acViewPreview, , "[EntryDate] = #" & Forms!frmWatchLogDatePicker.txtDate & "#", acHidden
DoCmd.OutputTo acOutputReport, "rptDailyLog", acFormatPDF, strFullPath
DoCmd.Close acReport, "rptDailyLog"

Not sure if this will solve your problem, but maybe it will give you some ideas to deal with it.
 

Users who are viewing this thread

Top Bottom