1

我试图在我的访问项目中使用 vba,但是当我使用 DMin 函数在查询中查找最小值时,我反而得到了我创建的表单的当前值返回。

当我在代码的上下文之外运行 Dmin 函数时,它确实可以正常工作,但是当我尝试在我的代码中使用它时,我遇到了上面描述的问题。

我似乎无法理解 StackExchange 上的格式,所以这里是代码的 pastebin。

http://pastebin.com/XCNPfNYG

问题线在这里

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
4

1 回答 1

0

您似乎缺少必要的引号:

 DMin("[Price Each]", "qryBoxHistory", "[CalConcatID] = 133377"
于 2012-05-18T12:20:24.420 回答