Now that I have my script for sending accounts by email as an attached pdf working in Windows 10, I am trying to add a second but similar script because the adsl here often drops out before all 30 emails are sent and it's more than annoying for me as well as my customers to have to send the whole lot over and over until they are all sent successfully..
I was hoping to modify the script using AskC to find out the last successfully sent email, use that character string to look up the records until the last one sent was reached, and then start sending the remainder from there.
The table with the customer information is 'Customers2' and the field with the customer code in is a character string called 'cuscode'. They are 'numbers' from 001 to 030.
I can't get the askC part to work, it returns 'Invalid filter expression "last = "006"'. I suppose it must be a mismatch or askC doesn't work inside a script but I've been staring at it for hours and the help on askC I find very scarce.
'find next account to send by finding the last one actually sent
dim filter as c
dim order as c
dim options as c
dim description as c
dim show_all_flag as L
dim layout_name as c
dim layout_type as c
dim last as c
filter = "last = var->AskC_What_was_the_last_cuscode_sent"
order = "cuscode"
options = ""
description = "Saved Query: Last_account_sent"
show_all_flag = .f. 'user cannot turn off the query
layout_type = "browse" 'to open a form, set this to "form"
layout_name = "" 'This will open the default layout. You can also specify a named layout here
a5_open_layout(layout_type,layout_name,"account",filter,order,description,options,show_all_flag)
'should now know the last account sent as 'last'
parentform.commit()
tbl = table.current()
tbl.fetch_first()
while .not. tbl.fetch_eof()
query.filter = "cuscode = "+quote(alltrim(tbl.cuscode))
query.order = ""
'lookup("CUSTOMERS2.DBF", "CUSCODE = ", "") not got this far yet !
to_param = Lookup("Customers2","cuscode = "+quote(alltrim(tbl.cuscode)),"alltrim(email)")
if alltrim(to_param) > "" 'only execute this section if an email address is found
subject_param = "Monthly account from Laprima S.L."
message_param = "Your attached account covers the month of "+cmonth(date())+"."
'attachments_param = ""
'cc_param = a5_eval_expression("",local_variables())
'bcc_param = a5_eval_expression("[email protected]",local_variables())
if filefind.get(a5.Get_Path()+chr(92)+"Accounts "+cmonth(date()),FILE_FIND_DIRECTORY,"PN") = ""
dir_create(a5.Get_Path()+chr(92)+"Accounts "+cmonth(date()))
end if
:report.SaveAs("AccMonthly","PDF",query.filter,query.order,a5.get_path()+chr(92)+"Accounts "+cmonth(date())+chr(92)+"Acct "+alltrim(tbl.cuscode)+".pdf")
sleep(4)
'email_send(to_param,subject_param,message_param,a5.get_path()+chr(92)+"Accounts "+cmonth(date())+chr(92)+"Acct "+alltrim(tbl.cuscode)+".pdf","",bcc_param)
sleep(4)
end if 'end of section to create and send email if address found
tbl.fetch_next()
end while
fil.flush()
fil.close()
I was hoping to modify the script using AskC to find out the last successfully sent email, use that character string to look up the records until the last one sent was reached, and then start sending the remainder from there.
The table with the customer information is 'Customers2' and the field with the customer code in is a character string called 'cuscode'. They are 'numbers' from 001 to 030.
I can't get the askC part to work, it returns 'Invalid filter expression "last = "006"'. I suppose it must be a mismatch or askC doesn't work inside a script but I've been staring at it for hours and the help on askC I find very scarce.
'find next account to send by finding the last one actually sent
dim filter as c
dim order as c
dim options as c
dim description as c
dim show_all_flag as L
dim layout_name as c
dim layout_type as c
dim last as c
filter = "last = var->AskC_What_was_the_last_cuscode_sent"
order = "cuscode"
options = ""
description = "Saved Query: Last_account_sent"
show_all_flag = .f. 'user cannot turn off the query
layout_type = "browse" 'to open a form, set this to "form"
layout_name = "" 'This will open the default layout. You can also specify a named layout here
a5_open_layout(layout_type,layout_name,"account",filter,order,description,options,show_all_flag)
'should now know the last account sent as 'last'
parentform.commit()
tbl = table.current()
tbl.fetch_first()
while .not. tbl.fetch_eof()
query.filter = "cuscode = "+quote(alltrim(tbl.cuscode))
query.order = ""
'lookup("CUSTOMERS2.DBF", "CUSCODE = ", "") not got this far yet !
to_param = Lookup("Customers2","cuscode = "+quote(alltrim(tbl.cuscode)),"alltrim(email)")
if alltrim(to_param) > "" 'only execute this section if an email address is found
subject_param = "Monthly account from Laprima S.L."
message_param = "Your attached account covers the month of "+cmonth(date())+"."
'attachments_param = ""
'cc_param = a5_eval_expression("",local_variables())
'bcc_param = a5_eval_expression("[email protected]",local_variables())
if filefind.get(a5.Get_Path()+chr(92)+"Accounts "+cmonth(date()),FILE_FIND_DIRECTORY,"PN") = ""
dir_create(a5.Get_Path()+chr(92)+"Accounts "+cmonth(date()))
end if
:report.SaveAs("AccMonthly","PDF",query.filter,query.order,a5.get_path()+chr(92)+"Accounts "+cmonth(date())+chr(92)+"Acct "+alltrim(tbl.cuscode)+".pdf")
sleep(4)
'email_send(to_param,subject_param,message_param,a5.get_path()+chr(92)+"Accounts "+cmonth(date())+chr(92)+"Acct "+alltrim(tbl.cuscode)+".pdf","",bcc_param)
sleep(4)
end if 'end of section to create and send email if address found
tbl.fetch_next()
end while
fil.flush()
fil.close()
Comment