简体   繁体   中英

MS Access “This recordset is not updatable” in a SELECT query

I'm stumped regarding this message MS Access is giving me.

I am trying to run a SELECT query, with two sub-queries within it. All tables are local.

Could someone please explain to me why the following code is returning this error?

SELECT S.SKU, S.Date, S.[Order No], P.WSP, P.Average_Cost, S.[Item Status]
FROM [Item Detail Temp] AS S, [FD Worksheets Temp] AS P
WHERE [P].[SKU]=[S].[SKU] AND [P].[Date to use]=(SELECT MIN(P2.[Date to use])
                         FROM   [FD Worksheets Temp] P2
                         WHERE  P2.[SKU] = S.[SKU]
                         AND    P2.[Date to use] >= S.[Date]);

Giving it a google hasn't particularly helped. I have Macros enabled in security to make sure that wasnt it, and from what I can tell I dont have any sort of Grouping in the code above that could cause the error?

Additionally, I believe the code does work just fine, but the whole time the loading bar is up that message is displayed in the bottom left corner of the screen. It also runs incredibly slow, and i'm sure i have run this query in the past without that message showing up, and also much quicker than it is currently.

Many thanks

EDIT: After looking a bit more, I have found a few possible reasons:

"- It uses First(), Sum(), Max(), Count(), etc. in the SELECT clause. Queries that aggregate records are read-only. - There is a MIN() function, could that be causing it?

- It has a subquery in the SELECT clause. Uncheck the Show box under your subquery, or use a domain aggregation function instead."

- The fields in a JOIN are not indexed correctly: there is no primary key or unique index on the JOINed fields. There are no Unique Key fields, could that be the reason?

JOIN your table sources and use the domain aggregate function, DMin , to make your query updateable.

FROM
    [Item Detail Temp] AS S
    INNER JOIN [FD Worksheets Temp] AS P
    ON [P].[SKU]=[S].[SKU]
WHERE
    [P].[Date to use]=
        DMin
            (
                "[Date to use]",
                "FD Worksheets Temp",
                "[SKU] = " & S.[SKU] & " AND [Date to use] >= " & Format(S.[Date], "\#yyyy-m-d\#")
            );

Hans, I noticed you deleted you comment. I got it just in time, and it works perfectly. The query now runs in less than a second, compared to the 5-10 mins it was before.

I managed using the following:

SELECT S.SKU, S.Date, S.[Order No], P.WSP, P.Average_Cost, S.[Item Status]
FROM [Item Detail Temp] AS S, [FD Worksheets Temp] AS P
WHERE
        [P].[SKU]=[S].[SKU] 
    AND [P].[Date to use]=
            DMin
                (
                    "[Date to use]",
                    "FD Worksheets Temp",
                    "[SKU] = " & S.[SKU] & " AND [Date to use] >= " & Format(S.[Date], "\#yyyy-m-d\#")
            );

您的查询包含聚合函数MIN ,表应该使用JOIN子句连接,连接列也应该被索引,详细信息表应该使用具有唯一索引的列连接,通常是它的主键。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM