Full Version: Delete Command Not Working
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
foxtrojan
I used the following codes to delete form, but the form is not deleted
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
but if I go to the table I am able to delete it manually. Please help
accesshawaii
Try this instead.

CODE
DoCmd.DeleteObject acForm, "MyForm"
Peter46
Since you refer to both a form and a table I'm mot sure what you mean by this.

Are you trying to delete the form object from the application?
or are you trying to delete data that you can see in the form? (All data for all records or just the data for one record)?
foxtrojan
Thanks so much guys. Appreciate your help.
I am trying to delete the whole form, not the data in a form, Thanks again
accesshawaii
Then what I posted will work. If this is a recurring event, then you might want to include a check like below to avoid errors in the event that it has already been deleted.

CODE
Dim obj As AccessObject
Dim objCP As Object
Set objCP = Application.CurrentProject

For Each obj In objCP.AllForms
    If obj.name = "MyForm" Then
        DoCmd.DeleteObject acForm, obj.name
    End If
Next obj
foxtrojan
Thanks Dan
I've this error message :-
You can't delete the database object "frmManagementApproval" while
it's open.
Did I do something not right?
accesshawaii
You have that form open. It cannot be open if you're trying to delete it. Are you trying to delete the actual form or just the data?
foxtrojan
I want to delete the whole form togather with the data.
I've a Delete command button at the footer. I have alot of duplicated forms caused by User, so I open each form and if it is a duplicate, I click "Delete"
to get rid of it. Pleas ehelp
accesshawaii
Honestly, it would be faster to just sort the forms and delete them manually.
foxtrojan
Thanks Dan. Will do.
accesshawaii
Good luck with your project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.