简体   繁体   English

访问dlookup多个条件返回布尔值和订单类型不等于

[英]access dlookup multiple criteria Return Boolean And ordertype not equal to

Private Function AllowPurge(FileID As String) As Boolean
Dim result As Boolean
Dim i As Integer

i = DLookup("COUNT(*)", "OrderMaster", "OrderStatus='S' AND FileID=" & FileID, "AND OrderType='E'")
If i > 0 Then
    result = False
Else
    result = True
End If

AllowPurge = result
End Function

OrderStatus is either marked as shipped or open 'S' or 'O'. OrderStatus标记为已发货或打开为“ S”或“ O”。

I need to: 我需要:

  • Allow purge - if every single order, other than E orders, are still open. 允许清除-如果除E订单之外的所有单个订单仍处于打开状态。
  • Don't allow purge - if any order, other than an E order, is marked as shipped. 不允许清除-如果除E订单以外的任何订单都标记为已发货。

DLookup is for looking up an individual value. DLookup用于查找单个值。

DCount is for counting. DCount用于计数。

Try this one out: 试试这个:

Function AllowPurge(FileID As String) As Boolean

    AllowPurge = (0 = DCount("FileID", "OrderMaster", "OrderStatus='S' _
        AND FileID='" & FileID "' AND OrderType='E'"))

Exit Function

(assuming the table is called OrderMaster ) (假设该表称为OrderMaster

You were pretty close, except missing single quotes around the string, and missing a space, and had an extra comma. 您非常接近,除了在字符串周围缺少单引号,缺少空格和逗号之外。

The logic would have worked your way the same, this is just an alternate (shorter) form. 逻辑将以相同的方式起作用,这只是另一种(较短的)形式。

Thanks Lee Mac! 谢谢李麦克!

Based on your stated logic: 根据您陈述的逻辑:

I need to: 我需要:

  • Allow purge - if every single order, other than E orders, are still open. 允许清除-如果除E订单之外的所有单个订单仍处于打开状态。
  • Don't allow purge - if any order, other than an E order, is marked as shipped. 不允许清除-如果除E订单以外的任何订单都标记为已发货。

I would suggest the following: 我建议以下内容:

Function AllowPurge(FileID As String) As Boolean
    AllowPurge = IsNull(DLookup("FileID", "OrderMaster", "OrderStatus='S' AND FileID='" & FileID & "' AND OrderType<>'E'"))
End Function

Here, the function will only return True if every non-E-Order ( OrderType<>'E' ) is marked as Shipped ( OrderStatus='S' ). 在这里,仅当每个非电子订单( OrderType<>'E' )被标记为Shipped( OrderStatus='S' )时,该函数才返回True

Your current code seems to be testing for 'E-Orders' which have been shipped, and not checking whether every non-E-Order is open. 您当前的代码似乎正在测试已发货的“电子订单”,而不是检查是否已打开所有非电子订单。

Thanks for the response 感谢您的回应

I tried this and seems to be working: 我尝试了这个,似乎正在工作:

i = DLookup("COUNT(*)", "OrderMaster", "OrderType'E' AND OrderStatus='S' AND FileID=" & FileID)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM