Christine
Christine

Reputation: 31

Duplicate error in current scope vb 6

Can someone help me. I'm trying to display an alert msgbox with two different recordset in one form so whenever there is an expired medicine it will both display and alert at the same time. But it gives me an error "Duplicate error in current scope" In this line

Dim expirationdate As Date
Do While Not Adodc2.Recordset.EOF = True

'----------'

Private Sub Form_Activate()
    Dim expirationdate As Date
    Me.AutoRedraw = True
    Adodc1.Recordset.MoveFirst
    Do While Not Adodc1.Recordset.EOF = True
        With Main
            .Text4.Text = "" & Adodc1.Recordset.Fields("MedicineName")
            .Text1.Text = Adodc1.Recordset.Fields("genericname")
            .Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
            .Combo3.Text = Adodc1.Recordset.Fields("Expmonth")
            .Combo4.Text = Adodc1.Recordset.Fields("Expday")
            .Combo5.Text = 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
            Else
                Exit Sub
            End If
        End If
    Adodc1.Recordset.MoveNext
    Loop

    '________________'

    Dim expirationdate As Date
    Me.AutoRedraw = True
    Adodc2.Recordset.MoveFirst
    Do While Not Adodc2.Recordset.EOF = True
        With Main
            .Text10 = Adodc2.Recordset.Fields("roomno")
            .Text11 = "" & Adodc2.Recordset.Fields("MedicineName")
            .Text2 = Adodc2.Recordset.Fields("GenericName")
            .Text12.Text = Adodc2.Recordset.Fields("StockQuantity")
            .Combo10 = Adodc2.Recordset.Fields("Expmonth")
            .Combo11 = Adodc2.Recordset.Fields("Expday")
            .Combo12 = Adodc2.Recordset.Fields("Expyear")
        End With

        expirationdate = CDate(Combo10 & "/" & Combo11 & "/" & Combo12)

        datepicker2.Value = Format(Now, "MMM-DD-yyyy")

        If datepicker2 < expirationdate Then
            MsgBox "OK!", vbInformation, "Working"
        Else
            MsgBox "Medicine Expired!.", vbExclamation, " Warning!"

            If MsgBox("Do you want to delete " & Text11 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
                Adodc2.Recordset.Delete
                Exit Sub
            End If
        End If
        Adodc2.Recordset.MoveNext
    Loop

End Sub

Upvotes: 0

Views: 140

Answers (1)

jac
jac

Reputation: 9726

Try this. You are sometimes relying on the default properties of your controls. This is generally bad, so I added the properties. I also removed the Exit Sub line. If the user clicks No you don't want to exit the sub, you want to continue looping through the Adodc2 Recordset.

Me.AutoRedraw = True
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF = True
    With Main
        .Text10.Text = Adodc2.Recordset.Fields("roomno")
        .Text11.Text = "" & Adodc2.Recordset.Fields("MedicineName")
        .Text2.Text = Adodc2.Recordset.Fields("GenericName")
        .Text12.Text = Adodc2.Recordset.Fields("StockQuantity")
        .Combo10.Text = Adodc2.Recordset.Fields("Expmonth")
        .Combo11.Text = Adodc2.Recordset.Fields("Expday")
        .Combo12.Text = Adodc2.Recordset.Fields("Expyear")
    End With

    expirationdate = CDate(Combo10.Text & "/" & Combo11.Text & "/" & Combo12.Text)

    datepicker2.Value = Format(Now, "MMM-DD-yyyy")

    If datepicker2.Value < expirationdate Then
        MsgBox "OK!", vbInformation, "Working"
    Else
        MsgBox "Medicine Expired!.", vbExclamation, " Warning!"
        If MsgBox("Do you want to delete " & Text11.Text & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
            Adodc2.Recordset.Delete
        End If
    End If
    Adodc2.Recordset.MoveNext
Loop

Upvotes: 0

Related Questions