Microsoft访问VBA 填充占总记录百分比的字段



当我点击按钮command9我想使用 count 函数来计算有多少条记录匹配combo7Insp_Cat = 1,然后计算总记录的 20%。然后使用 Update 语句将字段Insp_Type更新为"C",将记录数限制为先前计算的总记录数的 20%。

这是我迄今为止的代码,但在计数行上出现语法错误。

Private Sub Command9_Click()
Dim strSql As String
Dim Rec_Qty As Integer
Dim Rec_Perc As Integer
'Return record count for all records in Tbl_Inspections matching WO_ID in Combo7 and Insp_Cat =1
Rec_Qty = Count (WO_ID & Insp_Cat) Where [WO_ID]= Me.[Combo7]& [Insp_Cat]=1 From Tbl_Inspections
Rec_Per = Rec_Qty * 0.2
'Update records for "C" 20% records using Rec_Per value in limit function of Update command
strSql = "Update Tbl_Inspections"
strSql = strSql & "Set Insp_Type = 'C' WHERE WO_ID = Me.Combo7 & Insp_Cat = 1 & Limit = Rec_Per"
CurrentDb.Execute strSql
End Sub

谁能帮忙?

不能在 VBA 中使用 Count(( 函数,只能在查询中或在窗体或报表上的文本框中使用。

DCount(( 和 VBA 中使用的其他域聚合函数。

连接文字文本和变量。

Rec_Qty = DCount("*", "Tbl_Inspections", "[WO_ID]= " & Me.[Combo7] & " AND [Insp_Cat]=1")

CurrentDb.Execute "Update Tbl_Inspections Set Insp_Type = 'C' WHERE WO_ID = " & Me.Combo7 & " AND Insp_Cat = 1 AND Limit = " & Rec_Per

最新更新