Results 1 to 4 of 4

Thread: [RESOLVED] recordset updating

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2007
    Location
    Cardiff, capital of Wales :-D
    Posts
    33

    Resolved [RESOLVED] recordset updating

    hi i searched for this problem but i wasnt to sure what to make of the answers in other topics.
    i have a problem with deleting a record, i get a "runtime error 3020 update or cancel update without addnew or edit". whilst i was reading other threads i noticed a few people saying there was an error in vb with where you should place the edit and update but i tried what people said but it didnt work for me. here is my code i am not sure what is wrong with it.

    Code:
    Private Sub cmddeleterecord_Click()
        reply = MsgBox("Are you sure you want to delete this mechanic?" & vbCr & "Once this mechanic has been deleted it can not be retrieved", vbYesNo, "Delete Driver?")  'Message box asking if the user is sure they want to delete this record
            If reply = vbYes Then 'Message box asking if the user is sure they want to delete this record
                datdriver.Recordset.Edit    'Allow the user to edit the current record
                datdriver.Recordset.Delete  'Delete the current record
                datdriver.Recordset.Update  'Update the table
                datdriver.Recordset.MovePrevious    'Moves to the previous record
                MsgBox ("This mechanic has been successfully deleted")  'Message box confirming the user has deleted the record
            Else
                msg = MsgBox("Deletion has been aborted", vbOKOnly, "No deletion")      'Message box confirming the current record will not be deleted
            End If
    EDIT: also when i F8 (debug) the error message occurs at the update part
    i know the commenting makes it look a bit messy but thats how i kinda like to do it. any help is much appreciated
    Last edited by coolevo89; Dec 4th, 2007 at 12:49 PM. Reason: more info

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: recordset updating

    Bound controls in general give you problems.

    I would run a simple SQL DELETE query using the Execute method of the database object.

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: recordset updating

    You should not be using .Edit / .Update unless you are changing field values in between.

    The .Delete is an entire command in itself, and does not belong between them.


    I would also recommend avoiding bound controls as Hack implied, for an explanation of the reasons see the "Why Bound Controls Are Evil" link in Hack's signature, or this article from our FAQs which also explains why the data control you are using (DAO) is even worse - and links to a tutorial on the recommended alternative (ADO code).

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2007
    Location
    Cardiff, capital of Wales :-D
    Posts
    33

    Re: recordset updating

    thanks guys, thats an interesting article in hacks sig, i think i will do it the way you suggested, i like how it says in the article using that method holds you back from being a true programmer lol

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