即時嘗試在我的訪問項目中使用vba,但是當我使用DMin函數在查詢中查找最小值時,我改爲獲取當前創建的窗體的值。Vin中的DMin返回查詢中的錯誤值
當我在代碼的上下文之外運行它時,Dmin函數確實工作正常,但當我嘗試在代碼中使用它時遇到了上述問題。
我似乎無法理解StackExchange上的格式,所以這裏是代碼的pastebin代替。
的問題行是在這裏
PastPrice = DMin([Price Each], "qryBoxHistory", "[CalConcatID] = 133377")
Option Compare Database
Option Explicit
Private Sub Save_Click()
Dim CurrentConcat As String
Dim PastConcat As String
Dim PastConcatGrab As Boolean
Dim txtbox As String
Dim PastPrice As Currency
Dim ExpPrice As Currency
CurrentConcat = Me!CurrentConcat 'Set current Concatenated ID to the ID on the form
PastConcatGrab = IsNull(DLookup("[CalConcatID]", "qryBoxHistory", "[CalConcatID] = CurrentConcat"))
If PastConcatGrab = True Then 'If lookup shows that no boxes have been entered under that ID then a message is displayed and the values saved
txtbox = MsgBox("This is a new box, no past prices exist", vbOKOnly, "Information")
DoCmd.RunCommand acCmdSaveRecord
Else
PastConcat = DLookup("[CalConcatID]", "qryBoxHistory", "[CalConcatID] = CurrentConcat")
PastPrice = DMin([qryBoxHistory]![Price Each], "qryBoxHistory", "[CalConcatID] = 133377")
ExpPrice = Me![Price]
If ExpPrice > PastPrice Then
txtbox = MsgBox("This Box is not being supplied at a discounted rate, box has NOT been saved", vbOKOnly, "Information")
Else
txtbox = MsgBox("This box is discounted, This price has been saved", vbOKOnly, "Information")
End If
End If
End Sub
DMIN是域聚合函數和意志返回最小值o f選定的域(表或查詢)在選定的限制內(where語句)所選字段(列)。你想做什麼? – Fionnuala
我希望從查詢「qryBoxHistory」中的「Price Each」中獲得最小值,其中字段「CalConcatID」等於我爲測試設置的任意值。 – VBwhatnow