I have been running this routine now for almost 2 years. In the past week, I'm getting an "Error 1146" when attempting to send pdf files to clients using the below piece of code. It is happening on the first attempt to e-mail.
What I find confusing is that I have a menu that allows me to build the reports and email them via buttons, and that process works using the same data!
Any help would be appreciated.
Tom
Code:
'*****there is code above this to build the PDF's and to establish the "F1" text file f1.write_line("Begin E-mail of Reports at "+time("h:0mAM")+" on "+date_format(date(),"Mon-d-yyyy")) email_msg = email_msg + crlf()+"Begin E-mail of Reports at "+time("h:0mAM")+" on "+date_format(date(),"Mon-d-yyyy") tblC = table.open("clients") 'debug(1) 'ui_msg_box("",text1) tblC.index_primary_put("Location") tblC.fetch_first() dim I as N dim K as N J=0 K=0 I=0 h = 0 while .not.tblC.fetch_eof() if tblC.Email_addr = "" .or. marked("clients") statusbar.Set_Text("skipping email report "+strtran(trim(tblC.location),"_"," ")) tblC.fetch_next() else if Skip >0 while h < Skip tblC.fetch_next() h = h+1 end while end if if I < N J=J+1 I=I+1 if tblC.Report_Hdr <>"" loc1 = tblC.Report_Hdr else loc1 = tblC.location end if pdf_filename = "C:\Forecast\reports"+chr(92)+trim(loc1)+"_Pavement_forecast.pdf" msg_text = "Attached is the Pavement Condition Forecast for "+strtran(loc1,"_"," ") param_to = trim(tblC.Email_addr) param_subject = alltrim(strtran(loc1,"_"," "))+" Pavement Condition Forecast" param_cc = "" param_bcc = "" param_msg = msg_text param_attachments = pdf_filename 'traceln(alltrim(str(K+I))+" sending email report "+strtran(trim(tbl1.location),"_"," ")+" to "+trim(tbl1.Email_addr)) [COLOR="Red"]'************************ HERE IS WHERE IT HAPPENS! **************************[/COLOR] statusbar.Set_Text(alltrim(str(K+I))+" sending email report "+strtran(trim(loc1),"_"," ")+" to "+trim(tblC.Email_addr)) email_Send(param_to,param_subject,param_msg,param_attachments) tblC.fetch_next() sleep(L) else statusbar.Set_Text("Sleeping for "+alltrim(str(M/60,5,2))+" minutes... DO NOT Disturb!") sleep(M) I=0 K=K+N 'tbl1.fetch_next() end if end if end while f1.write_line(alltrim(str(J))+" Reports Mailed by "+time("h:0mAM")+" on "+date_format(date(),"Mon-d-yyyy")) email_msg = email_msg + crlf()+ alltrim(str(J))+" Reports Mailed by "+time("h:0mAM")+" on "+date_format(date(),"Mon-d-yyyy") tblc.close() 'statusbar.Set_Text("") endit: f1.write_line("*** End Build and e-mail of Reports at "+time("h:0mAM")+" on "+date_format(date(),"Mon-d-yyyy"))
Code:
Index of Scripts ---------------- 1: auto Script Name ( 1): auto -------------------------------------------------------------------------------- 'Date Created: 16-Oct-2009 04:02:07 PM 'Last Updated: 03-Nov-2010 06:58:56 PM 'Created By : Thomas Henkel 'Updated By : Henkel 'get timing variables 'debug(1) Dim F1 as P Dim text1 as C Dim a1[5] as C dim L as N dim M as N dim N as N Dim Skip as N DIM EM as C = "N" text1 = get_from_file("C:\FORECAST\timing.txt") a1.initialize(text1) N = val(a1[1]) 'N is the nomber of e-mails to do in a batch L = val(a1[2]) 'L is the number of seconds to wait after each e-mail M = val(a1[3]) 'M is the number of seconds to wait between batches Skip = val(a1[4]) 'SKIP is the number of e-mails that had been sent in a previous attempt. EM = ut(a1[5]) ON ERROR goto ERROR_TEST 'debug(1) 'f1 is the pointer to a log file so that we have some record of what is happening with each run. dim tbl as P Dim tbl1 as P DIM tblC as P DIM repset as P 'debug(1) if file.exists("c:\forecast\replog.txt") f1 = file.open("c:\forecast\replog.txt",FILE_RW_SHARED) else f1 = file.create("c:\forecast\replog.txt",FILE_RW_SHARED) end if endloc = file.size("c:\forecast\replog.txt") f1.seek(endloc) f1.write_line("") f1.write_line("*** Begin Build and e-mail of Reports at "+time("h:mAM")+" on "+date_format(date(),"Mon-d-yyyy")) ans2 = ui_msg_box("National Weather Station","Have the reports been Built?",UI_QUESTION_SYMBOL+UI_YES_NO) if ans2 = 6 goto emailreps end if repset = set.open("reports") tbl = table.get("conditions") tbl1 = table.get("clients") tbl1.index_primary_put("Location") dim J as N Dim loc as C = "" DIM loc1 as C = "" J=0 'PleaseWait(.T.,"Building Reports...") REPSET.fetch_first() loc = tbl.Location loc2 = tbl1.Report_Hdr while .not.REPSET.fetch_eof() if tbl1.Report_Hdr <>"" loc1 = tbl1.Report_Hdr else loc1 = tbl.location end if if exist(padr(trim(tbl.location),35," "),"conditions","Location") pdf_filename = "C:\Forecast\reports"+chr(92)+trim(loc1)+"_Pavement_forecast.pdf" if file_exists(pdf_filename) file_remove(pdf_filename) end if dim rec_no as N recno = tbl1.recno() filt1 = "location="+quote(trim(tbl.Location))+".and. report_hdr = "+quote(loc2) query.filter = filt1 query.order = "" 'report.preview("Condition Letters",query.filter,query.order) report.SaveAs("Condition Letters","PDF",query.filter,query.order,pdf_filename) end if repset.fetch_next() while tbl.Location = loc .and. tbl1.report_hdr = loc2 .and. .not.REPSET.fetch_eof() repset.fetch_next() end while loc = tbl.Location loc2 = tbl1.report_hdr J=J+1 end while PleaseWait() f1.write_line(alltrim(str(J-1))+" Reports Built "+time("h:0mAM")+" on "+date_format(date(),"Mon-d-yyyy")) ui_msg_box("Note",alltrim(str(J-1))+" Reports Built") repset.close() 'tbl1.close() 'tbl.close() debug(1) 'PleaseWait(.T.,"E-Mailing Reports...") emailreps: tblC = table.open("clients") 'debug(1) 'ui_msg_box("",text1) tblC.index_primary_put("Location") tblC.fetch_first() dim I as N dim K as N J=0 K=0 I=0 h = 0 while .not.tblC.fetch_eof() if tblC.Email_addr = "" statusbar.Set_Text("skipping email report "+strtran(trim(tblC.location),"_"," ")) tblC.fetch_next() else if Skip >0 while h < Skip tblC.fetch_next() h = h+1 end while end if if I < N J=J+1 I=I+1 if tblC.Report_Hdr <>"" loc1 = tblC.Report_Hdr else loc1 = tblC.location end if pdf_filename = "C:\Forecast\reports"+chr(92)+trim(loc1)+"_Pavement_forecast.pdf" msg_text = "Attached is the Pavement Condition Forecast for "+strtran(loc1,"_"," ") param_to = trim(tblC.Email_addr) param_subject = alltrim(strtran(loc1,"_"," "))+" Pavement Condition Forecast" param_cc = "" param_bcc = "" param_msg = msg_text param_attachments = pdf_filename statusbar.Set_Text(alltrim(str(K+I))+" sending email report "+strtran(trim(loc1),"_"," ")+" to "+trim(tblC.Email_addr)) email_Send(param_to,param_subject,param_msg,param_attachments) tblC.fetch_next() sleep(L) else statusbar.Set_Text("Sleeping for "+alltrim(str(M/60,5,2))+" minutes... DO NOT Disturb!") sleep(M) I=0 K=K+N 'tbl1.fetch_next() end if end if end while PleaseWait() f1.write_line(alltrim(str(J-1))+" Reports Mailed by "+time("h:0mAM")+" on "+date_format(date(),"Mon-d-yyyy")) ui_msg_box("Note",alltrim(str(J))+" Reports Mailed") tblC.close() 'tbl.close() f1.flush() f1.close() end 'a5.Close() ERROR_TEST: SLEEP(90) RESUME 0 end End Script ( 1)---------------------------------------------------------------
Tom
Comment