Eljefegeneo
Still trying to learn
- Local time
- Today, 09:42
- Joined
- Jan 10, 2011
- Messages
- 902
Another mystery that is driving me crazy. To delete a record from a form, I normally use the following code which has been working just fine:
But on one form I keep getting the same error message:
Runtime error 2046:
The command or action 'DeleteRecord' isn't available now.
Deletions are allowed in the property box.
This is similar to the post: http://www.access-programmers.co.uk/forums/showthread.php?t=60046
And yes, the toolbar is hidden. So I added the code to unhide it first and still get the same error message. I then first unhide the toolbar manually through code on my startup screen, but still get the error message.
In post #10 of the above reference post I realized that I have a hidden form, but, always a but, this identical code works on other forms/records.
I then tried the following:
[FONT="]And the record is deleted just fine.
[FONT="]I also tried the following which works fine:
[FONT="]
[/FONT]
[/FONT][/FONT]
Also simple macro to delete works fine.
I realize that I have in essence solved my problem and should move on, but I would like to know why the VBA code gives me the error.
Code:
If MsgBox("Continue with Delete?", vbYesNo) = vbNo Then
Exit Sub
Else
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
End If
DoCmd.Close acForm, "frmMyForm"
Runtime error 2046:
The command or action 'DeleteRecord' isn't available now.
Deletions are allowed in the property box.
This is similar to the post: http://www.access-programmers.co.uk/forums/showthread.php?t=60046
And yes, the toolbar is hidden. So I added the code to unhide it first and still get the same error message. I then first unhide the toolbar manually through code on my startup screen, but still get the error message.
In post #10 of the above reference post I realized that I have a hidden form, but, always a but, this identical code works on other forms/records.
I then tried the following:
Code:
[FONT="]strSQL = "DELETE * FROM tbl[FONT="]MyTable[/FONT] WHERE ID = " & ID.Value
CurrentDB.Execute strSQL, dbFailOnError[/FONT]
[FONT="]I also tried the following which works fine:
[FONT="]
Code:
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings True
MsgBox "Record deleted!"
[/FONT][/FONT]
Also simple macro to delete works fine.
I realize that I have in essence solved my problem and should move on, but I would like to know why the VBA code gives me the error.