Introduction
For closing an active Access Form we can use several methods and apply certain tricks to enhance the overall look of the action used for it.
The simplest method is to click the window close button X, which everybody knows. The On Close Event of the Form is also triggered on this action and the programmer can take care of any unfinished work as the closing of other forms related to the main form etc. But, when more Forms are open at the same time then there is a chance that the user may close the wrong Form by clicking on the wrong X button on the top.
Command Button with Macro Hyperlink
I prefer to create a Command Button on a convenient location on the Form, like at the Footer or Header of the Form, and let the user click on it. Create a macro and link to the Command Button's Hyperlink SubAddress Property. My favorite name for the Macro is Hlink_Close and it will contain only the Close Action leaving the ObjectType and ObjectName parameters blank.
Click on the Hyperlink SubAddress Property of the Command Button and click on the build ... icon at the right side to open up the Edit HyperLink Dialog Control. Select the Object in this Database option from the Link To Options List which will show the Database Objects: Tables, Forms, etc., expand the Macro group and select the HLink_Close Macro, and click OK.
This method has an attractive feature when you point to the control with the Hyperlink SubAddress set with the Macro, the Cursor changes to a hand with the index finger pointing, as you see when you point the cursor on a Hyperlink on the Internet.
The same HLink_Close Macro can be used this way for any number of Forms on its Command Buttons, Labels, Images, or any other Object that has a Hyperlink SubAddress Property, to close a Form by clicking on the object.
PopUp Form Issue
This method will not work on a form with the Form's Popup Property set to Yes. In such case, if another form is present with the Form's Popup Property set to No, then that form will be closed leaving the original form untouched. If this is the only form open, then it will end up with an error message: can't follow the Hyperlink Macro Hlink_Close. Use an alternative method for Forms with Popup Property set to Yes, like: write an On Click EventProcedure for the Command Button and write a Docmd.Close action in the VB Module without any parameters.
If you need to change only the style of the Mouse Pointer to a hand while pointing the cursor on the control then insert a # symbol in the Hyperlink SubAddress Property of the Command Button.
Tip: You can Open External Files Like Word, Excel, etc. by setting the Hyperlink Address Property (not Hyperlink SubAddress) of the Command Button with an external File's location address. Select the Link to Option: Existing File or Webpage rather than Object in this Database from the Edit Hyperlink Dialog Control.
Click Next to see Opening Access Forms
[...] Solved: Amended macro action to 'Close' leaving the ObjectType and ObjectName parameters blank and deleted all the sub-macros. changed the form's Popup property from Yes to No Made the Hyperlink SubAddress property link to the new Close macro which now has no sub-macros. Found this article helpful: http://msaccesstips.com/2007/05/closing-forms/ [...]
ReplyDelete