Results 1 to 11 of 11
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete Record (2000)

    On a form I have a delete record button that I created from a wizard. What I would like to do is - when a person deletes a record instead of showing the next record in the database, I want a new record to appear. I added " RunCommand acCmdRecordsGoToNew" to the following code that is behind the delete record button.
    Is the code correct and will the users of the form run into any problems? Thanks for your help.....


    Private Sub Command13_Click()
    On Error GoTo Err_Command13_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    RunCommand acCmdRecordsGoToNew
    Exit_Command13_Click:
    Exit Sub

    Err_Command13_Click:
    MsgBox Err.Description
    Resume Exit_Command13_Click

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Record (2000)

    That should work. By the way, the code generated by the wizard is a bit antiquated (even in Access 2002, the wizard still generates Access 2 and Access 95 code <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>) You can replace the two lines

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

    by this single one:

    RunCommand acCmdDeleteRecord

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record (2000)

    I am testing the code by deleting a record and I am getting "The command or action "RecordGoToNew" isn't available now. Is there a way to get around this error message?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Record (2000)

    Oops, yes, this will happen if you're on the last record. After deleting the last record, the form automatically moves to a new blank record. RunCommand acCmdRecordsGoToNew then throws an error. Try DoCmd.GoToRecord Record:=acNewRec instead, that doesn't put up an error message if you are already on a new record.

    You will also run into problems if you click the button while on a new record. The easiest workaround is to add a test:

    If Me.NewRecord = False Then
    RunCommand acCmdDeleteRecord
    DoCmd.GoToRecord Record:=acNewRec
    End If

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record (2000)

    Still testing. When I start to enter a new record and I decide to delete it, I click on the delete button and nothing happens. The code currently looks like this:

    Private Sub Command13_Click()
    On Error GoTo Err_Command13_Click

    If Me.NewRecord = False Then
    RunCommand acCmdDeleteRecord
    DoCmd.GoToRecord Record:=acNewRec
    End If


    Exit_Command13_Click:
    Exit Sub

    Err_Command13_Click:
    MsgBox Err.Description
    Resume Exit_Command13_Click

    End Sub

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete Record (2000)

    Nothing happens because you have told Access not to do anything when NewRecord is true. Try this:


    If Me.NewRecord = False Then
    RunCommand acCmdDeleteRecord
    DoCmd.GoToRecord Record:=acNewRec
    Else
    Me.Undo
    End If
    Charlotte

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Record (2000)

    You could remove the If ... Then and End If lines again, but then, you'll get an error if you click the button in a new record before you have entered anything. Do you happen to have an AutoNumber field? If so, you could test for that being non-empty.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete Record (2000)

    Do you ever suspect that they have maintained a certain amount of "backward compatibility" just so they don't have to rewrite the A95 wizards? <img src=/S/innocent.gif border=0 alt=innocent width=20 height=20>
    Charlotte

  9. #9
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record (2000)

    The undo that Charlotte suggested seems to work. I do have an autonumber field - how do I test for being non-empty? What is the code and how does it fit into my present code? Thanks for your help

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Record (2000)

    Charlotte's solution is elegant, so why not keep that?

    Otherwise, you could try this:

    If Not IsNull(Me.[NameOfAutoNumberField]) Then
    RunCommand acCmdDeleteRecord
    DoCmd.GoToRecord Record:=acNewRec
    End If

    where you must substitute the correct name of the autonumber field.

  11. #11
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record (2000)

    I just thought that down the road if that code has a problem, It wouldn't hurt to have an alternative. Thanks to you both.

Posting Permissions

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