Share via

Getting a form to close in a command button

Anonymous
2010-02-03T22:00:42+00:00

I have a command button inserted on a form to take the user back to the switchboard and would like to include code after the "OpenForm" code that will close the current form upon clicking to exit to the switchboard. What code should I insert.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

ScottGem 68,810 Reputation points Volunteer Moderator
2010-02-05T18:08:01+00:00

I prefer to use:

Docmd.Close acform, "formname", acSaveNo

The acSaveNo prevents design and property changes. Specifically sorts and filters. If a user applies a filter and the form is saved on close, the next user will open the form with that filter in place. So you don't want those properties to be saved.


Hope this helps, Scott<> P.S. Please post a response to let us know whether our answer helped or not. Microsoft Access MVP 2009 Author: Microsoft Office Access 2007 VBA Technical Editor for: Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports and Queries

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-02-04T05:28:23+00:00

    As Kathy said, you need to add the arguments to the statement.

    When you type the code, is should pop up the arguments you need for it in a tidy little tip style window.


    • Doug

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-02-04T02:49:23+00:00

    When you inserted the docmd.close statement, did you add the arguments for the object type (ie acform) and your form name that you want to close?

    I just tested the following code and it worked successfully:

    Private Sub Command0_Click()

         DoCmd.OpenForm "Order Details"

         DoCmd.Close acForm, "Customer Details"

    End Sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-02-04T01:02:31+00:00

    Thank you, but I have already inserted the DoCmd.Close at the end of the code in the command button, but it didn't close the form. That is why I checked the forum. I inserted it after the OpenForm command's error message and before the EndSub and am not sure the is where it should be located.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-02-03T22:44:24+00:00

    Look into DoCmd.Close


    • Doug

    Was this answer helpful?

    0 comments No comments