2014-02-17 51 views
0

有人可以幫助我。我對此很難過。我所需要的只是在藥物過期時顯示警報消息。我的問題是,當我有兩種或兩種以上的過期藥物時,它不會警惕所有藥物,而是警告一種藥物。請幫助。彈出提醒vb 6

這裏是我的代碼

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 

回答

0

債券是正確的,您需要迭代您的記錄集以顯示每個已過期記錄的消息。

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 
+0

謝謝先生,但怎麼能同時顯示兩種或更多過期的藥物?我在Text4中遇到了一個問題,它只分配一個值。 – Christine

+0

請查看我對代碼所做的更改。它將繼續循環,直到處理完所有記錄。 – jac

+0

它現在運作,先生謝謝:) 但我仍然有問題,當我試圖顯示不同表的過期藥物的價值。它給了我一個錯誤。 你能否看看我的第二篇文章?謝謝 – Christine

1

您可以通過所有的記錄在您的記錄需要循環。目前,您只能在FIRST唱片上進行操作。

Do Until Adodc1.Recordset.EOF 

    ' Assign values to textboxes, test date, etc. 

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

Loop 
+0

在這裏,我做了Sir.I仍然有同樣的問題。似乎我的代碼是錯誤的,我不知道如何循環它。我並不擅長vb。 「做,直到Adodc1.Recordset.EOF Adodc1.Recordset.Fields( 「MedicineName」)= Text4.Text Adodc1.Recordset.Fields( 「genericname」)= Text1.Text Adodc1.Recordset.Fields(「StockQuantity 「)= Text3.Text Adodc1.Recordset.Fields(」Expmonth「)= Combo3.Text Adodc1.Recordset.Fields(」Expday「)= Combo4.Text Adodc1.Recordset.Fields(」Expyear「)= Combo5。文本 Adodc1.Recordset.MoveNext 循環' – Christine

+0

它看起來像你分配到記錄集而不是從它像你原來的文章中。你不想要'Text4.Text = Adodc1.Recordset(「MedicineName」)'而不是?這會將記錄集中的值複製到文本框中。然後,在這個循環中添加你的日期檢查代碼,你應該很好。 – Bond

+0

我有一個問題先生用text4它只分配一個值。 我所需要的只是同時顯示所有過期的藥物,而沒有在text4中獲取記錄集的值。 如何做到這一點? – Christine