弹出警报vb 6

时间:2014-02-17 12:48:59

标签: vb6

有人能帮助我吗?我很难过。我需要的只是在药物过期时显示警告信息。我的问题是,当我得到两种或更多过期药物时,它不会提醒所有人。相反,它会提醒一种药物。请帮助。

这是我的代码

Private Sub Form_Activate()
    On Error Resume Next

    With Main
        .Text4 = Adodc1.Recordset.Fields("MedicineName")
        .Text1.Text = Adodc1.Recordset.Fields("genericname")
        .Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
        .Combo3 = Adodc1.Recordset.Fields("Expmonth")
        .Combo4 = Adodc1.Recordset.Fields("Expday")
        .Combo5 = Adodc1.Recordset.Fields("Expyear")
    End With

    Dim expirationdate As Date
    expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
    datepicker.Value = Format(Now, "MMM-DD-yyyy")
    If datepicker > expirationdate Then
        MsgBox Text4.Text & " is expired ", vbExclamation, "Warning!"
        If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
            Adodc1.Recordset.Delete
        ElseIf vbNo Then
            Exit Sub
        End If
    End If

End Sub

Private Sub Form_Load()
    Adodc1.CommandType = adCmdUnknown
    Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\clinic.mdb" & ";Persist Security Info=False"
    Adodc1.RecordSource = "select * from inventory order by Expyear asc"
    Adodc1.Refresh
    Adodc1.Refresh
End sub

2 个答案:

答案 0 :(得分:1)

您需要遍历记录集中的所有记录。目前,您只在FIRST记录上运行。

Do Until Adodc1.Recordset.EOF

    ' Assign values to textboxes, test date, etc.

    ' Fetch the next record...    
    Adodc1.Recordset.MoveNext

Loop

答案 1 :(得分:0)

Bond是正确的,您需要遍历记录集以显示已过期的每条记录的消息。

Private Sub Form_Activate()
    Dim expirationdate As Date

    On Error Resume Next    '<-- this is going to cause a problem if you never check for errors

    Adodc1.Recordset.MoveFirst    'make sure the control is positioned on the first record
    Do While Adodc1.Recordset.EOF = False    'loop over all of the records
        With Main
            .Text4.Text = Adodc1.Recordset.Fields("MedicineName")
            .Text1.Text = Adodc1.Recordset.Fields("genericname")
            .Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
            .Combo3 = Adodc1.Recordset.Fields("Expmonth")
            .Combo4 = Adodc1.Recordset.Fields("Expday")
            .Combo5 = Adodc1.Recordset.Fields("Expyear")
        End With

        expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
        datepicker.Value = Format(Now, "MMM-DD-yyyy")
        If datepicker > expirationdate Then
            MsgBox Text4.Text & " is expired ", vbExclamation, "Warning!"
            If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
                Adodc1.Recordset.Delete
            End If
        End If
        Adodc1.Recordset.MoveNext
    Loop

End Sub