The Forms of a Database Application: Form Maintenance |
|
Form maintenance includes deleting, copying, or renaming a form, etc. Most of these operations require that the form be closed. To manually delete a form, in the Forms section of the Database window, right-click it and click Delete. To programmatically delete a form, call the DeleteObject() method of the DoCmd object. Its syntax is: DoCmd.DeleteObject ObjectType, [objectname] The ObjectType argument must hold the value of acForm. The second argument is optional. Here is an example of callingthis method with only the first argument: Private Sub cmdDelete_Click() DoCmd.DeleteObject acForm End Sub |
If you omit the second argument and if a form is selected in the Forms section of the Database window, the selected form would be deleted. If no form is selected in the Forms section of the Database window and if you omit the second argument, you would receive a 2493 error stating that the action requires a form name: This means that, either you select a form prior to calling this method, or you pass the name of the form to delete as the second argument. If you create a new form, it automatically receives a temporary name but you must save it to have an actual name for the form. Once a form exists, if you want, you can change its name if you judge this necessary. In order to rename a form, it must be closed. To manually rename a form, in the Forms section of the Database window, you can right-click it and click Rename. This would put the name in edit mode, allowing you to type the new name and press Enter. To programmatically rename a form, you can call the Rename() method. of the DoCmd object. The syntax to use is: DoCmd.Rename(NewName, ObjectType, OldName) The first argument is the new name that the form will have. The second argument must be specified as acForm. The third argument is the name of the existing form that you want to rename. The form must exist in the database. Here is an example that changes the name of a form from Form1 to Specials: Private Sub cmdRename_Click() DoCmd.Rename "Specials", acForm, "Form1" End Sub Instead of renaming a form, you can make a copy of it and keep the original. To copy an existing form using the Microsoft Windows Save As routine, in the Forms section of the Database window, you can right-click the form and click Save As... This would open the Save As dialog box that allows you to enter the desired name of the copied form. Alternatively, you can right-click the form, click Copy, then right-click an empty area of the Forms section of the Database window and click Paste. This would open the Paste Table As dialog box in which you can enter the new name of the copied object. To programmatically copy a form, you can call the CopyObject() method of the DoCmd object using the following syntax: DoCmd.CopyObject [destinationdatabase][, newname], ObjectType, sourceobjectname] The destinationdatabase argument is the name or path of the database where the copied form would be sent to. If you are copying the form in the same database, you can omit this argument. The newname argument is the name that you want the new form to hold. The third argument must be acForm. The last argument is the name of the existing form. |
|
||
Previous | Copyright © 2005-2016, FunctionX | Next |
|