2017-05-22 63 views
0

當我點擊按鈕command9我想使用計數功能來統計有多少記錄匹配combo7Insp_Cat = 1,然後計算總記錄的20%。然後使用Update語句將字段Insp_Type更新爲「C」,將記錄數限制爲先前計算的總記錄數的20%。Microsoft Access VBA填充總記錄百分比的字段

這是我的日期代碼,但得到計數線上的語法錯誤。

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 

任何人都可以幫忙嗎?

+0

是在* Rec_Qty *線的僞代碼?因爲它在VBA中不兼容。另外,在更新查詢中的'Set'之前需要一個空格。 – Parfait

回答

0

不能在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