Date post: | 01-Jan-2016 |
Category: |
Documents |
Upload: | mary-figueroa |
View: | 37 times |
Download: | 0 times |
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Tutorial 4
Designing Complex Forms
Building the User Interface for the MovieCam Technologies Database
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Introduction to Forms
• Distinction between bound and unbound forms– an unbound form is not tied to any table or query.
• This form is used as an interface to the other database objects.– The buttons on the form, when pressed, perform some action but do
not work in conjunction with table data.– The unbound form example on page 142 is called a switchboard
because its purpose is to open other database objects such as forms and reports.
– bound forms.• The bound form is associated with an underlying table. When data
is entered into the bound form, the data in the table is manipulated accordingly.
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Unbound Form Example
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Bound Form Example
Toolboxin Access
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Form Design
• Forms are the user’s view of the database.– It is very common to provide an interface in which the user never
actually sees the Access environment at all. (Unbound form)– important that the interface is attractively laid out, easy to navigate,
and requires the least amount of “learning curve”. • The more the interface looks like Windows-based application,
the easier it will be for the user to learn.• User Interface - mechanism by which the user communicates and
interacts with the application. From the user’s perspective, the user interface is the application.
• ScreenTip - A message that appears when the pointer is positioned on a control on a form or on a button on a toolbar
• Splash Screen - A form that opens automatically when a database is opened, and is designed to give the user something to view while the application is loading
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Form Design guidelines goals
1. Look and feel like Windows (Office)Input text boxes – white background, sunken special effectOutput text boxes – flat effect same background color as form
2. Simple is better – avoid too many colors and fonts (group information)
3. Be direct – linear, intuitive ways to accomplish tasksOrganize controls logically, keystroke shortcuts on command buttons
and menus
4. Provide feedback – ScreenTip messagesScreenTip is a message that appears when pointer is over a control
on a form or toolbar button (short and informative)
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Classroom Activity
• go through Form Design consider each of the goals. – may not have thought about the interface accustomed to
using in Windows-based applications.
– Open one of the common dialog boxes in an application• Print dialogue box in Word, Excel, or PowerPoint.
• review this dialogue box and discuss why the developers made their decisions as to what kind of control should be used for each option in the dialog box.
• formulate suggestions of how the dialogue might be better designed for even greater “User-friendliness”.
– Be sure they consider things like color, layout, and choice of controls.
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Print Dialog Box
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Form Template vs. Form Master
• form template - establish default property setting, form size, and form sections (i.e., the basic structure for all forms in the database). – if form template not created, all new forms are based on the Normal form
template.– works exactly the same way as a Word template– The form template does not have any controls in it.
• form master - specify controls common to all forms in the database.– New forms take on the characteristics of the Form Template but NOT the
form master. – form master must be copied and pasted to new forms. So all new forms will
be based on the form template and then, where it is desired, the form master will be copied to the new form.
• think through design of a database BEFORE beginning.– If wait until all the forms created, these techniques are immaterial because forms
already completed • want common elements to be applied to the existing forms, much more work will
be involved then if had created the template and master ahead of time.
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Identifier Operators
• Identifier Operators - Operators that are used in expressions, macros, and VBA code to identify objects and their properties– Bang Operator (!) - An operator that is used to
separate one object from another or from the object collection.
• Collection - An object that contains a set of related objects– (Forms collection – all open forms in database)
• Dot Operator - An operator that is used to separate an object from its property or method
• Zero-Based - An object which begins its counting with the number 0.
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Identifier Operators (example code)
• Forms![Orders]![OrderDate].DefaultValue– This identifier refers to the value of the DefaultValue
property of the OrderDate control on the Orders form
• Forms![Orders]![OrderID]– The OrderID control on the open Orders form
• Reports![Invoice]![WarehouseName].Visible– The Visible property of the WarehouseName control on
the Invoice report
• In short, the exclamation point separates elements of a collection and the period indicates that what follows is an Access-defined property or method.
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Creating Switchboards
• Switchboard - An unbound form that is used to navigate to other forms, queries and reports in the database.– should be planned out way in advance of actually creating
them in Access. • The database developer should sit down, away from
the computer, and determine what forms, queries, and reports will need to be opened by the user.
• The developer will want to consider the most logical arrangement of the switchboard controls and whether more than one switchboard will be required.
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Working with Macros
• Macro - A command or series of commands that you want Access to perform automatically for you– Actions - The commands in a Macro.
• Macros in Access are different from Macros in the other Office applications. – In Excel, any action can be recorded in an Excel macro, can be
repeated by running the recorded macro. – In Access there is no macro recorder. A macro is collection of
predefined commands called actions. Macros are usually “triggered” when a particular event takes places.
– VBA is an Event-driven programming language. – list of arguments for the OpenForm actions
• every action has its own set of arguments
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Naming Macros and Macro Groups
• Develop standard naming convention for macros and macro groups
• Name an individual macro according to name of object initiating macro followed by object’s event property– Example: if click event of command button named cmdNext
executes a macro (macro name is cmdNext_Click)
• Macro group name same name as form associated with preceded by letter “m”– mcrGlobal – name used for group of generic macros used in
many different forms and reports
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Events
• Event – specific action recognized by an object– Each event has an associated event property that
specifies how an object responds when event occurs• Event properties listed in property sheet of forms,
reports, and sections of them
• Can specify name of macro or VBA procedure in the event property of an object causing it to run when the event occurs
– Event-driven programming – use of event properties to run macros or to execute VBA code.
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Arguments for OpenForm action
• Form Name – name of the form to open• View – Form, Design, Print Preview, Datasheet, PivotTable,
or PivotChart• Filter Name – specify name of a filter saved as query to filter
records• Where Condition – SQL WHERE clause (without the word
WHERE) selects records• Data Mode – settings correspond to form properties Allow
Edits, Allow Deletions, Allow Additions, and Data Entry• Window Mode – Minimized (Icon), Hidden, Dialog (set Modal
and Pop Up properties to Yes)– Modal – cannot use other open windows until current window closed– Pop Up – form stays on top of other open windows
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
OpenForm Actions
Tutorial 4 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications
Event-Driven Programming
• Event - A specific action recognized by an object when it occurs on or with that object, and for which you can define a response (Click, Double-Click, Right-Click)
• Event Property - A property that specifies how an object responds when an event occurs
• Event-Driven Programming - The use of event properties to run macros or to execute VBA code
• Event Procedure - A group of statements that execute when an event occurs, and is part of a larger category of procedures called sub procedures.