[英]Recordset is not updatable (query from two tables)
I am using Microsoft Access 2013 with Sharepoint lists and I have two tables: 我将Microsoft Access 2013与Sharepoint列表一起使用,并且有两个表:
=> there are many students with different starting dates =>许多学生的开学日期不同
=> in each student' study time, they may have some "weeks off" that are not counted in the total number of weeks that they have studied for. =>在每个学生的学习时间中,他们可能有一些“假”没有计入其学习的总周数中。
I am creating a query to calculate the number of weeks that students have studied from their Start_Date
. 我正在创建一个查询,以计算学生从
Start_Date
开始学习的周数。
SELECT
students.ID,
students.[Full name],
students.Mobile,
students.Start_Date,
Round((Date()-students.[Start_Date])/7,0) -
( SELECT SUM(
IIF( [Weeks Off].[From Date]> students.[Start_Date] and [Weeks Off].[From Date]<Date(),
[Weeks Off].[Number of Weeks], 0 )
)
FROM [Weeks Off]
) AS [Studied Weeks],
FROM students;
The problem now is that even though the query successfully displays all students with a column showing their "Studied Weeks", the Recordset is not updatable. 现在的问题是,即使查询成功地在所有学生的列中显示了“学习周数”,但记录集还是不可更新的。
How can I make it updatable again? 我该如何使其再次可更新?
From comment: 来自评论:
I changed it into: 我将其更改为:
(Round( ( Date()- students.Start_Date)/7,0) -
DSum("[Number of Weeks]", "[Weeks Off]",
"[From Date]>= students.Start_Date And [From Date]<= Date()")
) AS [Studied Weeks]
But it says: Microsoft cannot find the name students.Start_Date you entered in the expression. 但它说:Microsoft找不到学生的名字。您在表达式中输入的起始日期。 So I'm still stuck here.
所以我仍然停留在这里。
See: Dealing with Non-Updateable Microsoft Access Queries and Allen Browne: Why is my query read-only? 请参阅: 处理不可更新的Microsoft Access查询和艾伦·布朗 ( Allen Browne):为什么查询是只读的?
From the latter: 从后者:
It uses First(), Sum(), Max(), Count(), etc. in the SELECT clause.
它在SELECT子句中使用First(),Sum(),Max(),Count()等。 Queries that aggregate records are read-only.
汇总记录的查询是只读的。
It might work if you put the calculation into a separate query and join that (on Student.ID) to the Students table. 如果将计算结果放到一个单独的查询中(并将该查询(在Student.ID上)加入“学生”表,则可能会起作用。
It will work (but may be slower) if you convert the SUM calculation into a DSum()
expression. 如果将SUM计算转换为
DSum()
表达式,它将起作用(但可能会更慢)。 Then only that column will be read-only. 然后,只有该列将是只读的。
Edit 编辑
students.Start_Date
is a variable in your DSum
call, so it must be outside the constant string in the criteria. students.Start_Date
是DSum
调用中的变量,因此它必须在条件中的常量字符串之外。
Use Gustav's CSql()
function to format the date and concatenate it with the rest. 使用Gustav的
CSql()
函数格式化日期并将其与其余日期连接在一起。
(Round( ( Date()- students.Start_Date)/7,0) -
DSum("[Number of Weeks]", "[Weeks Off]",
"[From Date]>=" & CSql(students.Start_Date) & " And [From Date]<= Date()")
) AS [Studied Weeks]
should do it. 应该这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.