SQL Code Disappears from Query when sending EMail (1 Viewer)

RogerCooper

Registered User.
Local time
Today, 14:59
Joined
Jul 30, 2014
Messages
746
I have a simple SQL query that is e-mailed when there are >0 records. Fairly consistently, the SQL code in the query is wiped out and the query fails. It happens consistently to this query, even though I have many similar queries. Does anyone have an idea about what is happening. I am running Access 2013 in Windows 7

SELECT AR.[Inv#], [History Header].[PO#], AR.[Customer Name], AR.Date, AR.Mdse, AR.Freight, AR.Amount, AR.[Due Date]
FROM (AR INNER JOIN [History Header] ON AR.[Inv#] = [History Header].[Inv#(number)]) LEFT JOIN [Advanced Engineering Payment Reminder Sic] ON [History Header].[Inv#(text)] = [Advanced Engineering Payment Reminder Sic].ID
WHERE (((AR.[Customer Name])="ADVANCED ENGINEERING") AND ((AR.Amount)>0) AND ((AR.[Due Date])<=Date()) AND (([Advanced Engineering Payment Reminder Sic].ID) Is Null))
ORDER BY AR.[Inv#];
 
I have no idea what you mean when you say the SQL query disappears?
You have a query saved call "myQuery" and it gets changed without you doing anything?

edit: And seriously remove the # from that field name. That will cause a massive amount of problems!
 
I have no idea what you mean when you say the SQL query disappears?
You have a query saved call "myQuery" and it gets changed without you doing anything?

edit: And seriously remove the # from that field name. That will cause a massive amount of problems!
Yes, the query is being changed just because I sent an e-mail. I have had this occur on rare occasions with other queries, but mostly this one gives me trouble.

I doubt that "#" is the problem, I have hundreds of queries referencing Inv# and PO# working every day without a problem
 
Please tell us more about this
Yes, the query is being changed just because I sent an e-mail.

Changed how? Before and after images would be a help.
 
You open up the SQL view for the query and there is nothing there.
 
Did you save the query?
Are you saying, you were in the query designer, built a query and executed it and it just disappeared? Access never gave you an opportunity/asked if you wanted to save the query?
 
what is the code for sending the query?
 
Did you save the query?
Are you saying, you were in the query designer, built a query and executed it and it just disappeared? Access never gave you an opportunity/asked if you wanted to save the query?
The query saves no problem. It only erases when an e-mail is sent.
 
what is the code for sending the query?

DoCmd.SendObject acSendQuery, QueryName, acFormatXLSX, EMailAddress, CC, , QueryName & " " & KeyField & " " & CurrentKey, IIf(IsNull(MessageText), QueryName & " " & CStr(NRecords) & " Records" & ColumnWidthWarning, MessageText), False

QueryName, KeyField,MessageText,ColumnWidthWarning are strings
NRecords is a long integer.

Messagetext = "The attached invoices are now due. Please process for payment."
QueryName = "Advanced Engineering Payment Reminder"
 
have you tried putting a breakpoint on the docmd, run the code and once the docmd has run checking the query before further code runs to confirm it is the docmd that is causing the problem and not a bit of further code further on.

have you tried taking error checking off to see if any errors are generated?

Other thoughts is that there is a corruption in the code or the query - for the code try decompiling and see if that makes a difference. For the query, copy the sql into a text file and save the file, then delete the sql in the query then copy the text from the text file into a new query (don't just paste the sql you originally copied) . I have occasionally had issues with the querydef object becoming corrupted (and nothing visible in the code or settings) and this seems to solve it

This looks like a credit control process and the customer name is similar to your query name - is this a coincidence? or is there something that might be relevant - for example maximum number of characters for a query name is, I believe, 64. Although this query name is below this limit - perhaps not with a customer with many more characters in their name?

I'm not sure of the mechanics of docmd.sendobject but if (and I don't know if it does) it creates a temporary file then the character limit for that is 255 chars including the path so again, long names may be causing an issue.
 
have you tried putting a breakpoint on the docmd, run the code and once the docmd has run checking the query before further code runs to confirm it is the docmd that is causing the problem and not a bit of further code further on.

have you tried taking error checking off to see if any errors are generated?

Other thoughts is that there is a corruption in the code or the query - for the code try decompiling and see if that makes a difference. For the query, copy the sql into a text file and save the file, then delete the sql in the query then copy the text from the text file into a new query (don't just paste the sql you originally copied) . I have occasionally had issues with the querydef object becoming corrupted (and nothing visible in the code or settings) and this seems to solve it

This looks like a credit control process and the customer name is similar to your query name - is this a coincidence? or is there something that might be relevant - for example maximum number of characters for a query name is, I believe, 64. Although this query name is below this limit - perhaps not with a customer with many more characters in their name?

I'm not sure of the mechanics of docmd.sendobject but if (and I don't know if it does) it creates a temporary file then the character limit for that is 255 chars including the path so again, long names may be causing an issue.
Next time this happens, I will try deleting the object, recompiling the database and recreating it from scratch. Thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom