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: Introducing Forms
|
|
- Start Microsoft Access and open the GCS1 database you started in Lesson
9
- 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
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: Naming a Form
|
|
- To save the form, on the Form Design toolbar, click the Save button
- Set the name to Central
- Click OK and close the form
- To create another form, on the Form Design toolbar, click the arrow of the
New Object button and click Form
- In the New Form dialog box, make sure Design View is selected and click OK
- To save the form, on the main menu, click File -> Save
- Type CleaningOrders as the name of the new form and press Enter
- Close the form
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
Learning: Using AutoForm
|
|
- On the main menu of Microsoft Access, click Insert -> Form
- In the New Form dialog box, click AutoForm: Columnar
- In the combo box, select IdentityCards
- Click OK and notice that a new form is generated
- To save the form, click its System Close button
- When asked whether you want to save it, click Yes
- 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
Learning: Using AutoPage
|
|
- On the main menu of Microsoft Access, click Insert -> Page
- In the New Data Access Page dialog box, click AutoPage: Columnar
- In the combo box, select Identities
- Click OK and notice that a new Data Access Page is generated
- To save the page, click its System Close button
- When asked whether you want to save it, click Yes
- Accept the suggested name of the page and click Save
|
|