我有以下想要使用的VBA代码,然后才意识到它不正确;
<input class="defaultInput" [ngClass]="{'inputerror':emptyFields}" formControlName="idAnnuaire" placeholder="Ex: c20011">
我希望代码执行的操作是检查Len(DLookup("Service_User_ID", "tblPurchaseOrders", "Service_User_ID=" & .Person_ID) > 0) And IsNull(DLookup("Purchase_Order_Number", "tblPurchaseOrders", "Purchase_Order_Number='" & .Purchase_Order & "'"))
的记录是否存在Purchase_Order_Number
。
答案 0 :(得分:1)
只需检查 Null :
Found = Not IsNull(DLookup("Service_User_ID", "tblPurchaseOrders", "Service_User_ID = " & .Person_ID & " And Purchase_Order_Number = '" & .Purchase_Order & "'"))
答案 1 :(得分:0)
我不确定我是否正确理解了您的表字段,因为我认为Purchase_Order_Number是唯一的?如果是这样,为什么需要Service_User_ID?
无论如何,试试这个。
将其包装在一个函数中,以便能够从多个位置调用它。
Function OrderExists(ByVal purchaseOrder As String, ByVal personId As Long)
OrderExists = DCount("Purchase_Order_Number", "tblPurchaseOrders", "Purchase_Order_Number='" & purchaseOrder & "' AND Service_User_ID=" & personId) > 0
End Function
要打电话:
Sub T()
Dim bool As Boolean
bool = OrderExists("ABCD", 112)
Debug.Print bool
End Sub