簡體   English   中英

Do While 循環掛起

[英]Do While loop hangs

如果輸入滿足 Do...While 條件,則下面的循環將掛起。

  1. 此代碼旨在首先檢查組合框中輸入的產品代碼 (Me!Combo_Product_number) 是否存在於查詢 Q_compatible_FCM_EU 的產品代碼字段中。

  2. 如果存在,它將測試合規性。 如果在 T_DOSSIER_FPL 的 PURE_QP1 字段中找到其所有 PURE_QP1(對於特定產品可以有多個),則該產品是合規的。 如果未找到至少其中之一,則它不合規。

Private Sub Command455_Click()
Dim db As DAO.Database
Dim rst As Recordset
Dim rst1 As Recordset

If Nz(Me!Combo_Product_number) <> "" Then
   Set db = CurrentDb
   Set rst = db.OpenRecordset("Q_compliant_FCM_EU", dbOpenDynaset)
   Set rst1 = db.OpenRecordset("T_DOSSIER_FPL", dbOpenDynaset)

   rst.FindFirst "[PRODUCT_CODE] = '" & Me!Combo_Product_number & "'"
   If Not rst.NoMatch Then

       Do While Not rst1.EOF

        rst1.FindFirst "[PURE_QP1] = '" & rst.Fields("PURE_QP1") & "'"

        If Not rst1.NoMatch Then
            rst1.MoveNext
        Else
            MsgBox ("Product code is NOT compliant to FPL")
            Exit Sub
        End If

       Loop

       MsgBox ("Product code is compliant to FPL")

   Else
       MsgBox ("Product code is not available")
   End If

End If

End Sub

上面的代碼有什么問題?

DLookup用於此類簡單的任務,例如:

Dim PURE_QP1 As Variant

If Nz(Me!Combo_Product_number) <> "" Then

    PURE_QP1 = DLookup("[PURE_QP1]", "[Q_compliant_FCM_EU]", "[PRODUCT_CODE] = '" & Me!Combo_Product_number & "'")
    If IsNull(PURE_QP1) Then
        MsgBox ("Product code is not available")
    Else
        If IsNull(DLookup("[ID field of T_DOSSIER_FPL]", "[T_DOSSIER_FPL]", "[PURE_QP1] = '" & PURE_QP1 & "'")
            MsgBox ("Product code is NOT compliant to FPL")
        End If
    End If

End If

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM