錯誤:「運行時錯誤‘3061’參數太少預計2錯誤的一個記錄,但相同的SQL工作別處
我寫了這個簡單的函數,返回的記錄數計算的剩餘百分比變化。它應該是當用戶更新名爲「百分比」我確信下面的代碼應該工作,但是很明顯的東西是錯誤的領域發生它發生就行了。
Set rs = db.OpenRecordset("SELECT Tier1, [Percentage], Tier3 AS Battalion, Month " _
& "FROM tbl_CustomPercent " _
& "WHERE (((Tier1)=[Forms]![frmEntry]![cmbImport_T1]) AND ((Month)=[Forms]![frmEntry]![cmbMonth]));", dbOpenSnapshot)
我不知道它可能會失敗當完全相同的查詢是使用「百分比」文本框填充表單的「記錄源」時
Function RemainingPercentAvailable() As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Tier1, [Percentage], Tier3 AS Battalion, Month " _
& "FROM tbl_CustomPercent " _
& "WHERE (((Tier1)=[Forms]![frmEntry]![cmbImport_T1]) AND ((Month)=[Forms]![frmEntry]![cmbMonth]));", dbOpenSnapshot)
Dim CurrentTotal As Single
CurrentTotal = 0
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
CurrentTotal = CurrentTotal + rs!Percentage
rs.MoveNext
Loop
End If
RemainingPercentAvailable = "Remaing available: " & Format(1 - CurrentTotal, "0.000%")
Set rs = Nothing
Set db = Nothing
End Function
這確實奏效。謝謝。我想知道爲什麼我有其他例子偶爾起作用? – monty327 2014-12-13 18:24:32
對於那些工作的實例,你是否直接以DAO.Recordset方式打開查詢? – HansUp 2014-12-13 18:27:25
這是另一個實例: – monty327 2014-12-14 18:32:31