Error 2046

zzteam

Registered User.
Local time
Today, 06:15
Joined
Nov 24, 2005
Messages
36
I use MS Office 2007.
I make table and along every line i make delete button.
I put code for button:

Private Sub Command4_Click()
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings False
End Sub

but when I click on delete button on empty record I recive message:
Run-time error '2046'
The command or action 'deleteRecord' isn't available now.
How can I stop this error because I dont want access message" are you sure that you want to delete, bla, bla'

Any idea?

Thank you in advance
 
Try putting it inside an If/Then block

If Not Me.NewRecord Then
...
End If

By the way, you want the SetWarning line before the delete, and don't forget to set them back to True after.
 
Can you explain me how, please.
I try but without effects.

I made it.
Thank you very much!

Code is now:
Private Sub Command4_Click()
DoCmd.SetWarnings False
If Not Me.NewRecord Then
DoCmd.RunCommand acCmdDeleteRecord
End If
End Sub
 
Last edited:
Tested using the 2003 wizard created delete code, worked as expected.

Code:
  If Not Me.NewRecord Then
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
  Else
    MsgBox "new"
  End If
 
Re: Error 2046 DoCmd.RunCommand acCmdDeleteRecord

I was surprised to get the same message reusing the code in a different form. Access 2007

Debug window err.description
The command or action 'DeleteRecord' isn't available now.
? err.Number
2046
? iif( me.NewRecord, true, false)
False
0

this situation picks an existing record from one table. and calls:
40 DoCmd.SetWarnings False
50 DoCmd.RunCommand acCmdSelectRecord
'DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
60 DoCmd.RunCommand acCmdDeleteRecord
' error generated here
' still not sure what is causing this.

Found Solution:
My workstation was new last Friday:
It had MS Access SP2 and MSO SP3 installed.
After going to the MS update center and updating dozens of critical patches I started to program.
In my haste, a few Non-Access patches were skipped.

Today, the few remaining patches were updated for Word, Excel, Power Point, and .NET framework
I also went throught any existing updates related to office or Access and if it offered an "repair" button, I clicked on it.

Rebooted the workstation (as I had done when this error was persistant) and everything works perfectlly. No code changes.

Hope that helps someone else.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom