-
delete method
hello,
How do I prevent from getting an error when deleting the last record of a recordset using VB5.
sample code:-
Private Sub cmdDelete_Click()
Dim response
response = MsgBox("Delete current Record", vbOKCancel, "DELETE RECORD")
If response = vbOK Then ' User chose Yes.
With Data1.Recordset
.Delete
.MoveNext
If .EOF Then .MoveLast
End With
End If
End Sub
Thank you.
-
Re: delete method
Shah,
Use the following code
private Sub cmdDelete_Click()
Dim response
on error goto ThisError 'Extra care for trapping the error
response = MsgBox("Delete current Record", vbOKCancel, "DELETE RECORD")
If response = vbOK then ' User chose Yes.
With Data1.Recordset
if NOT .EOF
.Delete
end if
.MoveNext
If .EOF then .MoveLast
End With
Goto Last
thisError:
Last:
End If
End Sub
I hope this solves your problem. Do not forget to disable On error Goto command so that you can trap other errors...
Santulan
-
Re: delete method
Thanks for the tip. The function work but after running, the routine my cursor change to the hour glass and it never stop.
-
Re: delete method
Shah,
Please try to remove this line
If .EOF then .MoveLast
This may play innocence.
Thanks.
Santulan
-
Re: delete method
while not data1.eof
data1.delete
wend
-
Re: delete method
Hi Shah,
It´s too easy, in the begining of the sub write on error resume next.
It works pretty well and it´s faster than others commands.
So would you like to learn how to use SQL to work with your databases, it´s better than data control, not so easy but more flexible.
Private Sub cmdDelete_Click()
Dim response
ON ERROR RESUME NEXT --> When occur any error it will jump to the next command line
response = MsgBox("Delete current Record", vbOKCancel, "DELETE RECORD")
If response = vbOK Then
With Data1.Recordset
.Delete ---> IT DELETE THE REGISTER
.MoveNext --> IT CONFIRM THE DELETION
If .EOF Then .MoveLast --> IF eof THEN WILL GENERATE AN ERROR BECAUSE DON´T HAVE
A REGISTER TO MOVE LAST
End With
End If
End Sub
Leandro de Avelar
System Engineer
National Institut of Telecommunications