Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to close form/sub form

Status
Not open for further replies.

barit

Technical User
Jun 29, 2004
38
CA
When I close a form using a command button on the form Access shuts down saying "....Access encountered a problem and needs to close......". This error does not occur if I use the close action in the toolbar or on the menu.


My form is comprised of a main form and a subform. What am I doing wrong or what would be causing this problem to occur? I have tried using the following code to close the form with my command button.

DoCmd.Close

I have also tried DoCmd.Close acForm, "ToDo"

I really need help with this. The ability to have command buttons on my main form that control both the main and subform actions are quite important to me.

Thanks in advance.
 
In the On Click event of the Close button try using the following:

DoCmd.Close acForm, "Form Name", acSaveNo


HTH

An investment in knowledge always pays the best dividends.
by Benjamin Franklin
Autonumber Description - FAQ702-5106
 
How are ya barit . . . . .

Are you using the name of the Form or Subform?

Either way, use the main form name.

Calvin.gif
See Ya! . . . . . .
 
As mentioned by TheAceMan1, use the main form name, but I,m not sure Access should be that unfriendly just because a reference might be mistyped or wrong, so I suspect there might be some corruption, so if the above doesn't work, try importing all objects to a new database or recreate the form, or try Decompile or how to reduce Microsoft Access MDB/MDE size and decrease start-up times, which has resolved lot of such issues on my setup.

BTW - to add to mph1's suggestion, when closing from the main form, using

[tt]docmd.close adform, me.name[/tt]

could also be used.

Roy-Vidar
 
Thanks to all for responding. I tried all suggestions including decompiling and then recompiling. No luck.

I finally tried the same procedures with another form and subform and it worked. I then recreated a whole new form replacing the subform that was problematic, this seems to have worked.

Something must have been corrupt but for the life of me I can't figure out what. Thanks again for the suggestions.

I do however have another question since now I can get my form and subform to close via a command button on my form.

When I attempt to add a delete and undo buttons, they do not work. However, if I use the menu/toolbar to accomplish this task it works.

In the case of the delete button I get an error message #3200 "The record cannot be dleted or changed because table 'tblGift' includes related records.(tblGift is the table used as the record source for the subform. I obviouisly need to put some code behind the button that identifies I want to delete the selected record in the subform. I am not sure how to do this.

In the case of undo, once again I can complete the task from the menu/taskbar however from a command button on my form I get message telling me to complete the required data entry for the record (This is an error message I have set up in the subform). If I want to undo a record, how do I get the focus moved to the main form so I can complete the undo task?

Thanks again for your help to date. I really would appreciate some suggestions on how to deal with the additional command buttons.

 
OK barit . . . .

Glad ya got it fixed.

Could you start another thread with buttons problems. All would be able to see how it was resolved!

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top