CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: delete method

  1. #1
    Join Date
    Sep 1999
    Posts
    92

    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.


  2. #2
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    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


  3. #3
    Join Date
    Sep 1999
    Posts
    92

    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.


  4. #4
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    Re: delete method

    Shah,

    Please try to remove this line
    If .EOF then .MoveLast
    This may play innocence.

    Thanks.
    Santulan


  5. #5
    Join Date
    Jul 1999
    Posts
    35

    Re: delete method

    while not data1.eof
    data1.delete
    wend


  6. #6
    Join Date
    Sep 1999
    Location
    Minas Gerais - Brazil
    Posts
    5

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured