Home

The Forms of a Database Application

 

Form Fundamentals

 

Introduction to Form Creation

A visual application such as a computer database usually starts with a rectangular object that hosts other controls. Such an object is a form. In Microsoft Access, you can create a form that stands on its own like the forms of other programming environments, or you can create a form that is tied to a list. This means that the process of creating a form may depend on how you proceed.

To manually create a new form, on the main menu of Microsoft Access, you can click Insert -> Form. This would display the New Form dialog box where you can click Design View and click Ok. If you are already in the Forms section of the Database window, you can double-click the Create Form In Design View link or button. This would directly start the new form in Design View.

To programmatically create a form, call the CreateForm() method of the Application object. The syntax of this method is:

CreateForm([database[, formtemplate]])

The first argument to this method is the name of the database that will receive the form. If the form will be added to the current database, you can omit this argument. The second argument is the name of an existing form that you want to use as template. If you specify this argument, you must make sure that you provide the name of a form. Otherwise, you can omit it.

Here is an example:

Private Sub cmdCreateForm_Click()
    Dim frmEmployees As Form
    
    Set frmEmployees = CreateForm
End Sub

Practical Learning Practical Learning: Introducing Forms

  1. Start Microsoft Access and open the GCS1 database you started in Lesson 9
  2. On the Database window, click Forms.
    To create a new form, in the Forms section of the Database window, double-click Create Form in Design View

Naming a Form

When you have just created a form, it displays dully on the screen. Before designing, while designing, or after designing the form, it is a good idea to save it. To do this, you can click the Save button on the Standard toolbar and provide its name. The name of a form follows the rules of objects in Microsoft Access. This means that it can be as bizarre as possible. In our lessons, here are the rules we will use to name our forms:

  • The name will start with a letter, usually in uppercase
  • After the first letter, the name may consist of digits, letters, and underscore
  • The name will not contain special characters
  • In some cases, we will allow empty spaces in a name. In most cases, we will avoid including empty spaces in a name

Practical Learning Practical Learning: Naming a Form

  1. To save the form, on the Form Design toolbar, click the Save button
  2. Set the name to Central
     
    Save As
  3. Click OK and close the form
  4. To create another form, on the Form Design toolbar, click the arrow of the New Object button and click Form
  5. In the New Form dialog box, make sure Design View is selected and click OK
  6. To save the form, on the main menu, click File -> Save
  7. Type CleaningOrders as the name of the new form and press Enter
  8. Close the form

A Form From a Table

While the table is probably the most appropriate object for you, it may not be convenient to most users. An alternative is to create a form and make it user friendly. Fortunately, Microsoft Access provides fast means of creating a form.

The AutoForm is a feature that allows you to easily generate a form with little to no effort. To use it:

  • In the Tables section of the Database window, first select the table that holds the data. Then, on the Database toolbar, click the arrow of the New Object button and click AutoForm. Normally, by default, when Microsoft Access starts, Autoform is selected already on the New Object button. This means that, after selecting the table, you should be able to simply click the New Object button and a new form would be generated
  • In the same way, if you have already selected a table in the Database window, on the main menu, you can click Insert -> AutoForm and this would generate a new form
  • On the main menu of Microsoft Access, you can click Insert -> Form. In the New Form dialog box, click AutoForm: Columnar. In the combo box, select the table that holds the data, and click OK

After the AutoForm has generated a new form, you are able to enter new information into its Windows controls. You should also save the form if you want to preserve it.

Practical LearningPractical Learning: Using AutoForm

  1. On the main menu of Microsoft Access, click Insert -> Form
  2. In the New Form dialog box, click AutoForm: Columnar
  3. In the combo box, select IdentityCards
     
  4. Click OK and notice that a new form is generated
  5. To save the form, click its System Close button
  6. When asked whether you want to save it, click Yes
  7. Accept the suggested name of the form and click OK

A Data Access Page From a Table

A Data Access Page is another convenient object that can assist the users of your database. It is web-based object but appears like a form. As done for a form, you can easily create a normal DAP by using a the AutoPage. To do this:

  • On the main menu of Microsoft Access, you can click Insert -> Page. In the New Data Access Page dialog box, click AutoPage: Columnar. In the combo box, select the table that holds the data, and click OK
  • From the Pages section of the Database window, click the New button. In the New Data Access Page dialog box, click AutoPage: Column. In the combo box, select the table that holds the data, and click OK

Practical LearningPractical Learning: Using AutoPage

  1. On the main menu of Microsoft Access, click Insert -> Page
  2. In the New Data Access Page dialog box, click AutoPage: Columnar
  3. In the combo box, select IdentityCards
     
  4. Click OK and notice that a new Data Access Page is generated
  5. To save the page, click its System Close button
  6. When asked whether you want to save it, click Yes
  7. Accept the suggested name of the page and click Save

Using a Form

 

Selecting a Form

Some operations to perform on a form require that you select it first. If a form is opened on the screen, it may not have focus or it may not be activated. To select a form, you can click its title bar or any section of its body. If a form is closed, to manually select it, in the Database window, click the Forms button to activate its section. Then, click the name of the form. The name of the form would become highlighted, indicating that it is selected. Here is an example where a form named CD@Home is selected:

Selecting a Table in the Database Window

You can also select a form by pressing the up or the down arrow key continuously until the desired form is selected.

To programmatically select a form, use the DoCmd object that is equipped with the SelectObject() method. The syntax to use would be:

DoCmd.SelectObject acForm, [objectname][, indatabasewindow]

The first argument must be acForm to indicate that you are select a form. The second argument is the name of the form to select. If you only want to highlight the form in the Database window, then pass the third argument as True.

Here is an example that selects a form named Teachers to highlight it in the Database window:

Private Sub cmdSelect_Click()
    DoCmd.SelectObject acForm, "Teachers", True
End Sub

If the form is already displaying, it may be in the background. If there is no form by the name you specified in the second argument, you would receive a 2544 error:

If you omit the third argument or pass it as False, the form would be displayed in the foreground. If the form is not opened and you omit the third argument or pass it as False, you would receive a 2489 error:

You can use a conditional statement and error handling to make sure the user doesn't see this dialog box.

Opening a Form

Before using a form or performing an update in it, in most cases, you probably would need to open it first but this may depend on what you want to do at the time. This is because a form offers two main views. To simply and manually open a form, in the Forms section of the Database window, you can double-click. You can also right-click a form and click Open. This would open a form in Form View. Here is an example:

The second view of the form is used to design or modify the way a form looks. This is referred to as Design View. To open a form in Design View, in the Forms section of the Database window, you can right-click the desired form and and click Design View. If the form is already selected, on the toolbar of the Database window, you can click the Design button:

To programmatically open a form, you can use the DoCmd object that provides the OpenForm() method. Its syntax is:

DoCmd.OpenForm tablename[, view][, datamode]

The first argument of this method is the name of the table that you want to open.

The second argument is a constant value as follows:

View Name Result
acDesign The form will display in Design View
acFormDS The form will display like a table
acFormPivotChart The form will display as a pivot chart
acFormPivotTable The form will display as a pivot table
acNormal The form will display in Form View
acPreview The form will display in Print Preview

This second argument is optional. If you omit it, the acNormal option applies. Here is an example:

Private Sub cmdOpenForm_Click()
    DoCmd.OpenForm "Teachers", acNormal
End Sub

When this  code executes, a form named Teachers would be opened in Form View.

Instead of writing the code to open a form, you can use the Command Button Wizard that can do this for you. To do this, while the form is opened in Design View, make sure the Control Wizards button is down. Then, click the Command Button and click the form. The wizard would start and you can select the Open Form option after selecting Form Operations.

Practical Learning Practical Learning: Opening a Form

  1. To open the Central form, in the Database window, click Forms, then right-click Central and click Design View
  2. On the Toolbox, make sure the Control Wizards button is pushed .
    To automate the opening of a form,  click Command Button and click the top-left section of the form
  3. In the Categories list of the first page of the Command Button Wizard, click Form Operations
  4. In the Actions list, click Open Form
     
  5. Click Next
  6. In the second page of the wizard, click CleaningOrders and click Next
  7. In the third page of the wizard, click the text box and change its string to Cleaning Orders
     
  8. Click Next
  9. Change the name of the button to cmdOpenCleaningOrders and click Finish
  10. To view the code that was written, right-click the button and click Build Event...
     
    Private Sub cmdOpenCleaningOrders_Click()
    On Error GoTo Err_cmdCleaningOrders_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "CleaningOrders"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    Exit_cmdCleaningOrders_Click:
        Exit Sub
    
    Err_cmdCleaningOrders_Click:
        MsgBox Err.Description
        Resume Exit_cmdCleaningOrders_Click
        
    End Sub
  11. To return to Microsoft Access, on the Standard toolbar, click View Microsoft Access

Closing a Form

After using a form, you can close it if is (still) opened. If there is a structural change that needs to be saved, Microsoft Access would prompt you.

To manually close a form, you can click its system Close button Close or Close (Windows XP). You can also click File -> Close on the main menu if the form is active. You can also double-click its System button on the left side of its title bar. You can also press Ctrl + F4.

To programmatically close a form, you can call the Close() method of the DoCmd object. Its syntax is:

DoCmd.Close acForm, [objectname], [save]

The first argument must be specified as acForm to indicate that you want to close a form. If you are closing the same form that is calling this method, this is the only argument you would need. Consider the following example:

Private Sub cmdClose_Click()
    DoCmd.Close
End Sub

In this case, the form would be closed.

The second argument can be the name of the form you want to close. This argument is useful if you are trying to close a form other than the one that is making the call. Here is an example:

Private Sub cmdClose_Click()
    DoCmd.Close acForm, "Teachers"
End Sub

In this example, a form named is asked to be closed.

If you suspect that the form would need to be saved before formally being closed, you can pass the third argument with one of the following values:

View Name Result
acSaveNo The form doesn't need to be saved
acSavePrompt Prompt the user to save the changes. This is the default
acSaveYes Save the form without having to prompt the user

When calling the Close() method to close a form, if the form is not opened or if the specified form doesn't exist, nothing would happen (you would not receive an error).

Instead of writing your own code, to let Microsoft Visual Basic write it for you, you can use the Command Button Wizard.

The Properties of a Form

 

Introduction

A form appears as a rectangular object that occupies the necessary portion of the screen and is used to represent its application. A form by itself accomplishes little to no purpose. Its main role is revealed in its ability to be a container. That is, a form is mainly used to hold or host other controls. As a regular window, a form is equipped with a system icon, a title bar, one or more system buttons, borders, corners, and a body. Depending on the role of your form, you may want to design forms that present differing characteristics, even if these forms belong to the same database. For example, while one form presents a normal title bar, you may want another form not to present a title bar at all. While you may allow the user to be able to minimize or maximize a form, you may want to present one or both of these actions for the user. As an application design environment, Microsoft Access provides most of the features you will need for a regular and even advanced database product.

Referring to a Form

To refer to a form of a Microsoft Visual Basic application, you can use the Me keyword.

After creating a database, or while working on one, all of the forms that belong to it are stored in a collection called AllForms. As seen for the AllTables collection, AllForms is equipped with the Count property that holds the number of the forms that belong to the current database. Each form can be located by its name or its index, using the Item() property.

In Microsoft Access, a form is an object of type Form. A form that is opened in a database is a member of the Forms collection. To refer to an open form in your code, you can enter the Forms collection, followed by an exclamation point !, followed by the name of the form. Here is an example that refers to a form named Students:

Forms!Students

You can also include the name of the form between an opening square bracket and a closing square bracket but, if the name is in one word, then the square brackets are optional:

Forms![Students]

If the name is made of more than one word, then square brackets become required. Here is an example that refers to a form named Potential Applicants:

Forms![Potential Applicants]

If you omit the square brackets in this case, the expression or the code may not work.

A form can also be referred to by an index in the Forms collection. The first form of the collection has an index of 0 and can be accessed with Forms(0). The second form in the collection has an index of 1 and can be referred to by Forms(1), and so on. The name of the form can also be used as index. For example, a form named Students can be referred to as Forms("Students").

We mentioned that a form is mostly used as a container because it hosts some of the controls of its application. The controls that a form hosts are members of the Controls collection.

The Record Source

If a form has been designed or exists already but you want its Windows controls to display the values from a table, you can change its Record Source property to that of the table. After doing this, all columns from the table become available to controls on the form.

To programmatically specify the table that holds the data that would be made available to the controls on a form or a report, assign the name of the table to its RecordSource property. Here is an example:

Private Sub cmdRecordSource_Click()
    Me.RecordSource = "CleaningOrders"
End Sub

The System Menu

Like a regular window container, the form displays a title bar in its top section. On the left side of the title bar, it displays an icon. The system icon is fixed and you should not spend time trying to change it. The system icon holds a menu that allows the user to perform the regular operations of a Windows container, including minimizing, maximizing, restoring or closing the window. To display this menu, the user can click the formís system icon:

The presence of the formís system icon is partly controlled by the Control Box property of a form. In most cases, you should make this system icon and its menu available to the user. If for some reason you don't want to provide this functionality, set the Control Box property to No. The form would appear as follows:

If you decide to do this, make sure you provide the user with the ability to close the form and this type of title bar makes it impossible. Of course, a user may know that the form can be closed by clicking the Close menu item under the File group of the main menu or by pressing Ctrl + F4.

The Title Bar

The middle section of the title bar is actually referred to as the title bar. It can be used to change the view of the form after right-clicking it. The title bar uses a color set in the Advanced Appearance of Control Panel as Active Title Bar:

Since you cannot control and cannot predict how your users will modify their system colors (because most users are free to set their system colors as they wish, even when they work corporate), you should refrain from changing this color when designing your forms, especially if you plan to distribute your database. Otherwise, the result you see on your form may be different from your users computers.

When designing your forms, try to keep colors to their default and to their minimum. In this lesson, we are showing most options simply to let you know that they exist, not because you should or must change them.
 

The System Buttons

The right side of the formís title bar displays three system buttons Minimize , Maximize or Restore , Close . The group of these buttons is called the Control Box. If you do not want these system buttons at all, access the Properties window of the form and set the Control Box Boolean property to No from its Yes default value. In this case, the form would appear with neither the system icon nor the system buttons as seen above. Once again, if you do this, make sure the user has a way to close the form.

Instead of completely hiding all system buttons of a form, you can specify which ones to display and thus control the ability to close, minimize, or maximize the form. The presence and/or the role of the system buttons is (partly) controlled by the Control Box and the Min Max Buttons properties. When the Control Box property is set to No, regardless of the value of the Min Max Buttons property, there would be no system buttons on the title bar (this is also something you learn if you do Windows GUI programming, like Win32). Therefore, in order to control the appearance and behavior of the system buttons, the Control Box property must be set to Yes. The values of the Min Max Buttons produce the following results:

Min Max Buttons Result System Buttons Consequence
Minimize Maximize Close
None Hidden Hidden Available The form can only be closed
Min Enabled Enabled Disabled Available The form can be minimized or closed but not maximized
Max Enabled Disabled Enabled Available The form cannot be minimized but can be maximized
Both Enabled Enabled Enabled Available All operations (minimize, maximize, restore, and close) are allowed

Depending on the role and probably the number of Windows controls on a form, you will decide what button to allow or not.

To minimize a form, the user can click its Minimize button. To programmatically minimize a form, you can call the Minimize() method of the DoCmd object. Here is an example:

Private Sub cmdManipulate_Click()
    DoCmd.Minimize
End Sub

To maximize a form, the user can click its Maximize button. To programmatically maximize a form, you can call the Maximize() method of the DoCmd object. If a form is maximized, to restore it, the user can click the Restore button. To programmatically restore a form, call the Restore() button of the DoCmd object.

To close a form, the user can click its system Close button. As seen earlier, to close a form, you can call the DoCmd.Close method.

Practical Learning Practical Learning: Controlling the System Buttons of a Form

  1. To select the Central form, on the main menu, click Windows -> Central
  2. As the form is still in Design View, click the button at the intersection of its rulers
  3. In the Properties window, set its Min Max Buttons property to Min Enabled
  4. Save the form

The Formís Borders

Whether you allow the system icon and system buttons or not, the user needs to be able to know where a form starts and where it ends. This is seen by the borders of the form. In most cases, you will not be concerned with this aspect. Otherwise, you can control the borders of a form.

The borders of a form are controlled using the Border Style property. If you set it to None, the form would appear without borders:

 

The Form's Width

A form displays on the screen using its dimensions. These are the width and height. The form itself controls only the width. The height is controlled by its sections. To change the width of a form, in the Properties window, type the desired decimal value in the Width field of the Format property page. You can also change the form's width by dragging the right border of one of its sections.

The Detail Section

The most visible part of a form is an area called Detail. This section starts on a bar labeled Detail and ends at the bottom unless a new section starts. To programmatically access the Detail section of a form, if you working in an event of the form, you can use either Detail or Me.Detail

The Detail section serves as the main host of other controls. It can also serve to display messages of various kinds. The Detail section can be enhanced by manipulating its properties. These properties are not necessarily related to the parent form but can be used conjointly with it.

We mentioned earlier that the form itself controle its width. The vertical dimension of a form is controlled by its sections. This means that a section, such as the Detail section, can "decide" how much height it needs to accommodate its content. The vertical measurement of the Detail section is controlled by the Height property. There are two main ways you can change the Detail section's height at design time:

  • In the Format tab of the Properties window, you can change the value of the Height field. The value must be a natural or a decimal number. In reality it is a decimal number. If you type a natural number, also called an integer, it would be converted to decimal. If you type an invalid number, you would receive an error
  • You can position your mouse in the lower border of the Detail section until the mouse cursor changes into a vertical double arrow. Then click and drag. You can drag up to shrink the section or drag down to heighten it
     

To programmatically change the height of the Detail section, assign a constant natural or decimal value to its Height property. Here is an example:

Private Sub cmdChangeHeight_Click()
    Me.Detail.Height = 3.18
End Sub

The Header and Footer Sections

 

Besides the Detail section, a form can be enhanced with one or two more sections: Header and Footer.
By default, the Header and Footer sections are created on a form if you use the Form Wizard.

To add the Header and Footer sections on a form that doesn't have them, you can use the menu bar where you would click View -> Form Header/Footer. Probably the fastest way to add these sections is by right-clicking anywhere on the form and clicking Form Header/Footer. If the form already has these sections but they don't contain anything, they would be removed. If the form already has these sections and they contain anything, you would receive a warning:

If you still want to delete the Header and Footer sections, you can click Yes; this would un-recoverably delete their content.Like the Detail section, the Header and Footer sections control their own height, which you can change the same way we described above for the Detail section.

To access the Header section in your code, use the form's FormHeader property. Here is an example:

Private Sub cmdManipulate_Click()
    Me.FormHeader.Height = 2.24
End Sub

To programmatically access the Footer section, use the form's FormFooter property. 

 This also applies for the Back Color property. The Special Effect property allows you to raise or sink a section.

Practical Learning Practical Learning: Closing a Form

  1. To select a different form, on the main menu, click Windows -> Cleaning Orders
  2. To add the Header and Footer sections to the form, right-click the body of the form and click Form Header/Footer
  3. On the Toolbox, make sure the Control Wizards button is pushed , click Command Button and click the right section under the Footer bar of the form
  4. In the Categories list of the first page of the Command Button Wizard, click Form Operations
  5. In the Actions list, click Close Form, and click Next
  6. In the second page of the wizard, click the text box and change its string to Close
  7. Click Next
  8. Change the name of the button to cmdClose and click Finish
 

Record Selectors

The Record Selector is a vertical bar on the left side of a form. It allows the user to select all of the fieldsí contents of one or more records and copy them to the clipboard. Such a selection can then be pasted to another record, other records, or to a text or another type of file (for example you can paste the record in Notepad, Microsoft Word, Microsoft Excel, or any text file).

There are two reasons you would use record selectors on a form. If you want the user to be able to access all fields of a record as a whole, make sure that the form is equipped with record selectors. In the same way, you can hide the scroll bar if the user would not need them. Another reason you would use a record selector is for aesthetic reasons. Most of the time, if designing a form for data entry, you would mostly allow the presence of record selectors. If you are designing a dialog box that would display the same content all the time, you should not allow the record selectors.

The presence or absence of record selectors is controlled by the Boolean Record Selectors property field. If you set the field value to Yes, the form would display the record selector. Setting the field value to No would hide the record selectors. To programmatically control the presence or absence of the record selector on a form, assign a value of True (to display it) or False (to hide it) to the RecordSelector property of the form. Here is an example:
Private Sub cmdManipulate_Click()
    Me.RecordSelectors = False
End Sub
 

The Form's Scroll Bars

As much as you can, you should design your (non-Datasheet) form to display all of the fields of a record. Sometimes this will not be possible. If a form possesses too many fields, Microsoft Access would equip the form with one or two scroll bars. A scroll bar allows the user to scroll from one side of the form to another. The vertical scroll bar is used to scroll up and down while the horizontal scroll allows scrolling left and right.

By default, scroll bars come up if the form "judges" that some fields are hidden. The presence of scroll bars allows the user to be aware of hidden objects on the form. Depending on your design, you can control the appearance or disappearance of the scroll bars. To do this, change the value of the Scroll Bars field in the Format property page of the Properties window. There are four possible values. To display only the vertical scroll bar, set the value to Vertical Only. In the same way, you can display only the vertical scroll bar by selecting Horizontal Only. On the other hand, you can display both scroll bars by setting the value to Both. If for some reason you don't want any scroll bar, set the Scroll Bars property value to Neither.

To programmatically control the presence or absence of scroll bars, access the ScrollBars property of the form and assign one of the following four values:

Value Description
0 No scroll bar will display
1 Only the horizontal scroll bar will display
2 Only the vertical scroll bar will display
3 Both the horizontal and the vertical scroll bars will display
 

Navigation Buttons

When we study records, we will see that a form (also a table, a query, or a report) is equipped with some buttons in its lower section. These buttons allow the user to navigate back and forth between records. These buttons are very useful during data entry and data analysis. If you are creating a form that would display the same content all the time, such as a form that does not actually display records, you can hide the form navigation buttons.

The presence or absence of navigation buttons is controlled by the Boolean Navigation Buttons property. When its value is set to Yes, the form would display the Navigation Buttons. To hide them, set the Navigation Buttons property value to No.

To programmatically control the presence or absence of the navigation buttons, access the form's NavigationButtons property and assign the desired Boolean value. Here is an example:

Private Sub cmdManipulate_Click()
    Me.NavigationButtons = False
End Sub

Dividing Lines

A form is equipped with special horizontal lines used to visually separate sections of a form. They do not perform any other special function. They can be useful on a continuous form.

To equip a form with dividing lines, add a header and a footer sections. On the other hand, if you create a form that is directly equipped with a header and a footer sections, it would display the dividing lines.

The presence or absence of the horizontal lines is controlled by the Boolean Dividing Lines property. Its default value is Yes, which means that the dividing horizontal lines would display on the form. To hide both lines, you can set its value to No. To hide an individual line, you can completely reduce its section.

To control the presence or absence of the dividing lines of a form, access its DividingLines property and assign the desired Boolean value. Here is an example:

Private Sub cmdManipulate_Click()
    DividingLines = False
End Sub

Form Automatic Centering

By default, when a previously created and saved form appears, Microsoft Access remembers the previous position the form had and restores it. If you can make sure that the form is always centered when it comes up. To make this possible, the form is equipped with the Auto Center Boolean property. When set to Yes, this property causes the form to be centered when it displays to the user.

Dialog Boxes

 

Introduction

A dialog box is a rectangular object that is used to host or carry other controls without itself being hosted by another object:

Code Builder

The title bar on top of a dialog box has a title and the system close button (only, mostly). Although this is the classic appearance of a dialog box, it is not strictly exclusive. Some dialog boxes display the system icon. On the right side of the title bar, a classic dialog box displays only the system Close button made of X. Again, this is not exclusive. It is not unusual for a dialog box to display the minimize and the maximize/restore buttons but, according to Microsoft standards, a dialog box should appear as the one above: no system icon, only the system Close button, and a type of border referred to as Dialog Frame.

To use a dialog box, the user must open it one way or another. Your job is to decide how and when the user will be able to open a dialog box.

To create a dialog box in Microsoft Access, you start from a form and display it in Design View. To convert an existing form into a dialog box, set its Border Style property to Dialog. This reduces the system buttons to the Close button only.

There are two types of dialog boxes: modal and modeless.

Modal Dialog Boxes

A dialog box is referred to as modal if the user must close it before continuing with another task on the same application.

The Date and Time dialog box of WordPad is an example of a modal dialog box: if opened, the user must close it in order to continue using WordPad. 

In order to use a dialog box in your application, you should analyze a scenario and define if the dialog box is necessary. Use a dialog box if you want the user to first terminate whatever task she would be performing. For example, if a user is performing a payment of an order processing, it is natural to process and finish that payment before starting another task.

A classic (or normal) dialog box would need neither a Record Selectors bar nor the record navigation buttons. Therefore, you should decide how the dialog box would be used. If you want a regular dialog box as defined by the Microsoft standards, you should set the Record Selectors, the Navigation Buttons and the Dividing Lines properties to No each.

Modal Dialog Box
 

Practical Learning Practical Learning: Creating a Dialog Box

  1. Select the CleaningOrders form and click the button at the intersection of its rulers
  2. To convert it into a dialog box and make other changes, change its properties as follows:
    Auto Center: Yes
    Border Style: Dialog
  3. Switch the form to Form View
  4. Click the created Close button
  5. When asked whether you want to Save, click Yes
  6. Right-click the Central form and click Form Header/Footer
  7. In the toolbox, click the Command Button and click the right side of the Footer section
  8. In the first page of the wizard, click Form Operations then Close Form, and click Next
  9. In the second page of the wizard, change the string in the text box to Close and click Next
  10. In the third page of the wizard, change the name to cmdClose and click Finish
  11. Save and close the form
  12. Close the database

Modeless Dialog Boxes

A dialog box is referred to as modeless if the user doesn't have to close it in order to continue using the application that owns the dialog box:

Modeless Dialog Box

The Find dialog box of WordPad (also the Find dialog box of most applications) is an example of a modeless dialog box. If it is opened, the user doesn't have to close in order to use the application or the document in the background. 

Since the modeless dialog box doesn't display its button on the task bar, the user should know that the dialog box is opened. To make the presence of a modeless dialog box obvious to the user, it typically displays on top of its host application until the user closes it.

To create a modeless dialog box, or to convert a form into a modeless dialog box, when in Design View, set the Popup property to Yes. This makes sure that the user can work on another form and the modeless dialog box or form would remain on top of any other form of the database.

 

Form Maintenance

 

Deleting a Form

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.

Renaming a Form

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

Copying a Form

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 © Yevol, 2007 Next