Results 1 to 3 of 3
  1. #1
    pjd71's Avatar
    pjd71 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Apr 2013
    Location
    Sunset Beach, NC
    Posts
    15

    Run time error When Delete Button is Hit and No Data in Form

    Have a form that works fine if there is data inputted within the form. The problem I have is that others will be using it and if someone hits the Delete button with no data in any field, then I get a Run-Time error ‘2046’: The command or action ‘DeleteRecord’ isn’t available now window popup with the options to debug or end. I am concerned if they hit debug, they could mess up the scripts. The form ID is a text ID which is created when information is filled in on the form. When debugging, the DoCmd line is highlighted. Basically, I don't want that error to pop up if not data is entered

    I have researched to find a solution and have not found a solution.

    Private Sub cmdDelete_Click()
    If MsgBox("Do you wish to delete this record?", vbYesNo, "Delete Confirmation") = vbYes Then


    If MsgBox("Continue, this request will not be processed?" & vbCrLf & _
    "This will permanently delete the record.", vbYesNo, "2nd Delete Confirmation") = vbYes Then
    DoCmd.RunCommand acCmdDeleteRecord
    End If
    End If
    End Sub
    Last edited by pjd71; 05-23-2013 at 04:51 PM. Reason: Edited Code for Viewing

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Wrap this code in another conditional that tests if record exists.

    Maybe:

    If Me.Recordset.Count = 0 Then
    MsgBox "No records. Delete request canceled"
    Else
    ...
    End If

    Or use error handler code to capture and deal with that specific error.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    pjd71's Avatar
    pjd71 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Apr 2013
    Location
    Sunset Beach, NC
    Posts
    15
    Thank you so much. Since it was a error with the deleted button and the results were going to be the same in this case, I use the On Error Resume Next. Thanks for point me in the right direction.

    Private Sub cmdDelete_Click()
    If MsgBox("Do you wish to delete this record?", vbYesNo, "Delete Confirmation") = vbYes Then
    If MsgBox("Continue, this request will not be processed?" & vbCrLf & _
    "This will permanently delete the record.", vbYesNo, "2nd Delete Confirmation") = vbYes Then
    On Error Resume Next
    DoCmd.RunCommand acCmdDeleteRecord
    End If
    End If
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 11-25-2012, 06:09 PM
  2. Replies: 2
    Last Post: 07-24-2012, 12:44 PM
  3. SQL DELETE with ID fails (data type error)
    By alangea in forum Programming
    Replies: 2
    Last Post: 05-11-2012, 06:12 PM
  4. Replies: 1
    Last Post: 10-11-2011, 11:16 AM
  5. Error while trying to add delete link button.
    By islandboy in forum Access
    Replies: 3
    Last Post: 09-03-2009, 09:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums