Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Closing Forms

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

Share:

1 comment:

  1. [...] 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

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code