'Complex Access Query does not refresh in Excel

My Excel applications exports data (6 columns by 300+ rows) to Access DB once a minute. After exporting, I try to import two sets of older values from Access to Excel.

The primary query is:

SELECT qryStDevPct.StDevPct, atblExcelIntraday.ValueClose  
FROM atblExcelIntraday 
LEFT JOIN qryStDevPct 
    ON atblExcelIntraday.SecurityID = qryStDevPct.SecurityID 
WHERE atblExcelIntraday.RecordDate Between #2022-05-04 13:55:59# And #2022-05-04 13:54:59# 
ORDER BY atblExcelIntraday.Ticker;

The internal Access qryStDevPct is:

SELECT atblExcelIntraday.SecurityID, 
       Avg(atblExcelIntraday.ValueClose) AS AvgP, 
       StDev(atblExcelIntraday.ValueClose) AS STD, 
       [STD]/[AvgP] AS StDevPct
FROM atblExcelIntraday 
INNER JOIN atblSecuritiesOpenPriceDaily 
   ON atblExcelIntraday.SecurityID = atblSecuritiesOpenPriceDaily.SecurityID
GROUP BY atblExcelIntraday.SecurityID;

The Price data from table always imports correctly, but StDevPct is either 0 or 1 30% of the time.

I can easily refresh it by doing manual "Data Refresh", but neither .Calculate, nor .QueryTables("qryPriceDB_1").Refresh work.

I could split it it two separate queries, but aside from programming it will take more time on the Excel end, and I'm trying to keep my main procedure to under 1,500 msec.

Please advise.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source