[Solved ] Error 2046 The command or action 'DeleteRecord' isn't available now.

Rx_

Nothing In Moderation
Local time
Today, 09:05
Joined
Oct 22, 2009
Messages
2,803
? Err.Number Result 2046
? Err.Description Result The command or action 'DeleteRecord' isn't available now.

The DoCmd.RunCommand acCmdSaveRecord will fail with that error message if you are stepping through the code. If you need a breakpoint, put it in the BeforeUpdate event itself or after the save depending on wher you want to start the debugging.

Example: Don't set a break point on line 80 to 110. A break point or stepping through will cause an error that won't occure at run-time. ;)

Note: this answer was on the bottom of page one of a two page post.
Came in Monday to validate my Delete code. A "new error" seemed to appear out of nowhere. These tags should improve the search.

Code:
Private Sub cmdDeleteRecord_Click()
      ' Delete the current record. A list box on top of the form needs to be refreshed to the new current record, or be informaed it was the last record
 
      Dim blArchiveStatus As Boolean
      Dim Answer As Integer
10        If Me.lstROW.ListCount = 0 Then Exit Sub        ' case no records in list box
15        Call LogUsage("cmdDeleteRecord_Click", "Form_ROW", "Delete called, User asked yes/no")  ' Custom function writes to log file
20    If Not blAddNewMode Then                      ' if adding a new record, don't run this code
30            On Error GoTo Err_cmdDeleteRecord_Click
40                Answer = MsgBox("Are you sure you wish to delete this record?", vbYesNo + vbExclamation + vbDefaultButton2, "Record Delete Confirmation")
50                If Answer = vbYes Then        ' To user: Your Final Answer
60                                              DoCmd.RunCommand acCmdSaveRecord   ' ensure text box edits are updated
70                                              blArchiveStatus = CopyCurrentRecordToArchive("ROW_Archives")      ' archive to archive table before delete
                                                ' note CopyCurrentRecordToArchive function works, no errors, creates a copy with no errors
80                DoCmd.SetWarnings False
                          'DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 ' code from Access 2000 before update
90                DoCmd.RunCommand acCmdSelectRecord
                          'DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
100                       If Me.Dirty Then Me.Dirty = False
110               DoCmd.RunCommand acCmdDeleteRecord        ' error.number 2046  The command or action 'DeleteRecord' isn't available now.
                   ' ****** Warning  stopping code with the debugger on the previous 3 lines will result in Error Number 2046
120               Me.Refresh
130               lstROW.SetFocus
140                                     lstROW.Requery
                ' ------------------------    after the delete, is there one record left or not?  update list box or disable list box---------
150                             If Me.lstROW.ListCount > 0 Then
160                                     lstROW.SetFocus
170                                     lstROW.Requery                    ' Somewhere here - we need to revisit what fielsd show visiable like orginal
180                                     Me.lstROW.Selected(0) = True      ' sets top record on list box to selected
                                        'Call lstROW_AfterUpdate           ' runs list box  ' old code - check to see if new procedure is used here
190                                     Call lstROW_Click                  ' highlights next row in list box - populates rest of fields
200                               Else ' that was the last record
                                    ' ************************ NEED Empty List box Exit Stratigy -------------
                                    'Call ActivateControlsByRegulatoryType("Empty", "Ohio") ' list is empty and ohio doesn't exist
210                               End If
220               DoCmd.SetWarnings True
225               Call LogUsage("cmdDeleteRecord_Click", "Form_ROW", "Delete called, User said Yes Process Completed")
230     Else
         Call LogUsage("cmdDeleteRecord_Click", "Form_ROW", "Delete called, User said NO as final answer")
240     End If
250
260    End If ' more than one record was there to delete
 
Exit_cmdDeleteRecord_Click:
270       Exit Sub
Err_cmdDeleteRecord_Click:
280       MsgBox Err.Description    ' error.number 2046  The command or action 'DeleteRecord' isn't available now.
290       Resume Exit_cmdDeleteRecord_Click
End Sub

http://www.access-programmers.co.uk/forums/showthread.php?t=164651
 
Last edited:

Users who are viewing this thread

Back
Top Bottom