Snowflake68
Registered User.
- Local time
- Today, 21:28
- Joined
- May 28, 2014
- Messages
- 464
I have the following code that deletes a subform (frmItemSelectionSubForm) and copies a template (DEFAULTfrmItemSelectionSubForm) and then renames it to the original subform name.
DoCmd.Close acForm, "frmItemSelection", acSaveYes
DoCmd.DeleteObject acForm, "frmItemSelectionSubForm"
DoCmd.CopyObject , "frmItemSelectionSubForm", acForm, "DEFAULTfrmItemSelectionSubForm"
DoCmd.OpenForm "frmItemSelection"
The procedure is called from the main form (frmItemSelection) (that contains the subform frmItemSelectionSubForm) via a button named 'RESET'. My code first closes the main form but then I get an error saying that it cannot delete the database object while it is open. But the main form and thus the subform is actually closed.
Why does Access think the form is still open when its not? Why do I get this error saying its open and is there away to get around it?
Its really difficult to explain why i want to delete and copy a form but basically its because I want to reset the subform and unhide all the columns that the user had chosen to hide. The form has over 50 columns so its easier to have a reset button to do this for them. The template has all of the columns unhidden so I thought that if i close the main form then recreate the subform that when the main form opens it will display all of the columns again.
I do have some code that unhides all columns in the subform which does work but not if the user hides/unhides columns and then navigates away to another form (the changes to the subform are saved) and when the user returns to the main form again and runs the code to unhide all columns on the subform from the main form does not unhide them because they have been previously saved as hidden in the subform.
I should also should point out that when the user navigates away from this main form it is done via a button called 'BACK' which runs a macro that closes the form (and saves it) then opens another form. I have to save the form when they navigate away because they go back and forth between several forms and it has to remember the columns they had visible previously until such time that they chose to reset them back to the default.
Really sorry for all the blabbering on I just dont know how to explain it any better.
Hope someone can help this damsel in distress.
DoCmd.Close acForm, "frmItemSelection", acSaveYes
DoCmd.DeleteObject acForm, "frmItemSelectionSubForm"
DoCmd.CopyObject , "frmItemSelectionSubForm", acForm, "DEFAULTfrmItemSelectionSubForm"
DoCmd.OpenForm "frmItemSelection"
The procedure is called from the main form (frmItemSelection) (that contains the subform frmItemSelectionSubForm) via a button named 'RESET'. My code first closes the main form but then I get an error saying that it cannot delete the database object while it is open. But the main form and thus the subform is actually closed.
Why does Access think the form is still open when its not? Why do I get this error saying its open and is there away to get around it?
Its really difficult to explain why i want to delete and copy a form but basically its because I want to reset the subform and unhide all the columns that the user had chosen to hide. The form has over 50 columns so its easier to have a reset button to do this for them. The template has all of the columns unhidden so I thought that if i close the main form then recreate the subform that when the main form opens it will display all of the columns again.
I do have some code that unhides all columns in the subform which does work but not if the user hides/unhides columns and then navigates away to another form (the changes to the subform are saved) and when the user returns to the main form again and runs the code to unhide all columns on the subform from the main form does not unhide them because they have been previously saved as hidden in the subform.
I should also should point out that when the user navigates away from this main form it is done via a button called 'BACK' which runs a macro that closes the form (and saves it) then opens another form. I have to save the form when they navigate away because they go back and forth between several forms and it has to remember the columns they had visible previously until such time that they chose to reset them back to the default.
Really sorry for all the blabbering on I just dont know how to explain it any better.
Hope someone can help this damsel in distress.
