run time error 3021. No Current Record

J0eydak!ng

New member
Local time
Today, 03:51
Joined
Aug 1, 2013
Messages
6
Hi,

I have a form which is used to input data into and delete data from a table. The form is made up of the fields, 2 buttons (add button and delete button) and a sub form which displays the data in the table; The sub form is requeried everytime i click any of the buttons.

The problem is when I delete. When I try to delete I choose the recordset from the subform and hit delete button, however if I try to delete any record apart from the one in the first row after having already removed a record I succeed; removing the record in the first row after having already removed a record I would be prompted with an error 3021 error.

The code lies below:

Code:
Private Sub btnDelete_Click()
   'Check Existing selected record
    If Not (Me.subContainerfrm.Form.Recordset.EOF Or Me.subContainerfrm.Form.Recordset.BOF) Then
            'confirm delete
        If MsgBox("Are you sure you want to delete this record?", vbYesNo) = vbYes Then
            'delete now
            CurrentDb.Execute "Delete From Container WHERE containerid=" & Me.subContainerfrm.Form.Recordset.Fields("containerid")
            'requery database
            Me.subContainerfrm.Requery
        End If
    End If
End Sub

Help is greatly appreciated.

Regards,

Joe
 
Try using the following:
Code:
            CurrentDb.Execute "Delete From Container WHERE containerid=" & Me.subContainerfrm.Form![containerid])
Else post your database with some sample data, (zip it)
 
First of all thanks for your reply JHB.

Worked perfectly.

Thanks for your advise :).

Have a good day :)
 

Users who are viewing this thread

Back
Top Bottom