Msgbox "Alarm: No record found. Unable to delete unfound record!"
rst.Delete ...
-Tom.
Microsoft Access MVP
>"Kevin" <kevin.pt
...@yahoo.com> wrote in message
>
news:62bf611e-271c-488c-a83f-d34703b86428@a31g2000yqn.googlegroups.com...
>>i am trying to delete an item from a list box by clicking on a
>> button. It's not working, obviously but the problem is that I dont
>> know why. I have this same code for list box 1 and it works just
>> fine. this one errors out on rst.delete with runtime 3021 : no
>> current record. What am i doing wrong??
>> Private Sub Command3_Click()
>> 'delete from list box2
>> Dim rst As DAO.Recordset
>> Set rst = CurrentDb.OpenRecordset("SELECT * FROM account WHERE
>> 'account type' = '" & Me.list2 & "'")
>> rst.Delete
>> Me.list2.Requery
>> End Sub
>Your SQL statement incorrectly puts quotes around the [account type] field.
>If you are going to do it via a recordset like that, this would be better:
>'------ start of amended code #1 ------
>Private Sub Command3_Click()
> Dim rst As DAO.Recordset
> With Me.list2
> If Not IsNull(.Value) Then
> Set rst = CurrentDb.OpenRecordset( _
> "SELECT * FROM account WHERE [account type] = '" & _
> .Value & "'")
> rst.Delete
> rst.Close
> End If
> .Requery
> End With
>End Sub
>'------ end of amended code #1 ------
>However, that is not the best way to do it. This would be better:
>'------ start of amended code #2 ------
>Private Sub Command3_Click()
> With Me.list2
> If Not IsNull(.Value) Then
> CurrentDb.Execute _
> "DELETE FROM account WHERE [account type] = '" & _
> .Value & "'", _
> dbFailOnError
> End If
> .Requery
> End With
>End Sub
>'------ end of amended code #2 ------