Escolar Documentos
Profissional Documentos
Cultura Documentos
Motivation
This document defines a set of guidelines for developers, creating MS
Access solutions. As MS Access is intended to be used by IT
professionals as well as by non professional end users likewise, it
includes functionality for both audiences which should not be mixed up.
Explanation
1 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
testing phase.
Explanation
But it is very important for the developer to know how the Name
AutoCorrect functionality works in background as it sometimes might
behave different than one expects (see also [2]). When knowing the
backgrounds, developer then needs to follow the following simple rules
to get the expected result out of this functionality:
Consider that Name AutoCorrect feature does not work on macros, data
access pages, VBA code, union queries, pass through queries and data
definition queries. It also does not populate changes from tables in
connected backend files to frontend files.
2 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Open each MS Access object after changing to start passing the change to
depended objects.
Open and close each table, query, form and report, one after another,
after renaming something, to allow the Name AutoCorrect feature to
detect the broken references properly.
After changing the name of one object, do not create a new object with same
name, before change has been populated to each dependent object.
Solution is, after changing name from table1 to table2, open form1, so
that Name AutoCorrect can correct the broken dependency. After that, a
new table1 can be created without any concerns.
The risk of not knowing how Name AutoCorrect feature works in detail
and not complying with the rules above is (while Name AutoCorrect is
still turned on), that this functionality yields to unintentionally behavior
and update or change of something might break relationship where
automatic healing were expected instead.
3 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
2. Architecture rules
Explanation
Where queries are used this way, there is a chance, that table design
changes (e.g. for performance improvements) may only lead to query
update without the need to touch reports and forms at all.
Accessing the same data from different tiers inside the application will
result in more complexity and confusion to the developer than needed.
The application will be harder to test, whether automatically or
manually. Familiarizing new developers to the project, or even same
developer after long time, due to enhancements, will be much more
complicated and time consuming.
Exceptions
However, in rare cases there might be necessity for VBA code to directly
operate on tables. For example in case of backend update, VBA code (in
frontend) may alter the tables and their relationships directly.
Explanation
4 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
be split up into two (or more) distinct files. The file or files containing
the backend should only contain tables holding data. The file or files
containing the frontend should contain any stored SQL statements as
well as GUI elements such as forms and reports.
When used by many users at the same time (file is stored at some
network location), the one-file-solution will become slow and
inefficient to use. Instead, deploy dual file solution in a way, where
the one and only backend file is stored at some network location
and the frontend files are stored on each users computer.
Updating the GUI after solution has already been gone into
productive use, the data, stored in tables, will be lost, or migration
is complicated and expensive. On a split up solution, update of GUI
is as easy as just deploying the frontend to the users computer
while still connecting to the old backend. Updating the backend
can be implemented by altering table structure from new frontend
as well without destroying productive data.
Explanation
Do not use lookup fields for foreign keys in tables itself. Use regular
integer ID to refer to primary key in other table instead.
In the case, where looked up data on foreign key fields is much more
helpful than the actual data, use an SQL query instead.
5 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Explanation
For describing tables and its fields, use description field in table
properties instead.
Explanation
One can even not restrict the format of that number, to generate e.g.
an exactly 6-digit voucher number or something similar.
Also there is not any need to reset the AutoNumber value to start with
zero or to any continuously sequential order with no gaps in between. It
just must not matter to any user or developer if the three only records
in the table have the AutoNumber values 0, 1, 2 or 25, 1034 and 567.
6 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
So, using this number for any additional meaning other than
unambiguousness may be really risky and uncontrollable.
Explanation
Enforcing this rule on table design level will help developers to not
oversee such of these rules during GUI or query design.
Explanation
All the rules, which allow or disallow a field to contain no data, NULL
data or zero length strings, can be summarized as integrity rules.
Additionally, rules for the integrity of field relationships among tables
(enforcing referential integrity, cascading deletion or update).
On forms level, there is high risk for the developer to forget the one or
other rule to be enforced or checked on each and every form and
control. The risk is too high then, that sooner or later the table may get
filled with data containing exceptional values or relationships that is not
expected by other forms or reports.
7 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Rule 3.6: Text fields should not allow zero length strings
Explanation
NULL data and Zero Length Strings are different content. Handling
them via VBA code need usage of different routines for checking or
writing these values. So, when accessing string fields of tables per VBA,
there is risk, that the developer may forget to handle all these
exceptional values.
Exceptions
NULL data and Zero Length String values are not only distinct values
but also have its very own meaning. NULL data means something like
Unknown. This is why a field, which has not been given content yet
(or on a new record), contains the NULL value, as the database doesnt
know anything about its content so far. In contrast, a Zero Length
String means something like known empty. In this case the database
definitely know that this field is empty (e.g. as it is explicitly entered
somehow or selected by user).
If it is really necessary to use both distinct content types for one field,
8 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
developer might consider using this explicitly. In this case special care
should be taken during VBA coding for this (or these) field(s). Also on
forms and reports both different values should be explicitly shown to the
user somehow and the user should get the ability to set the field(s) to
each of these values explicitly.
Explanation
Validation rules are also some kind of integrity rules as it enforces rules
regarding different fields of the same record. So, this is why validation
rules also need to be implemented on table level, like the other integrity
rules.
Explanation
All the more, instead of using input mask to constrain the values,
accepted by the table itself, make use of integrity rules, validation rules
and allow or disallow empty fields, NULL values and zero length strings.
Using this feature on table design level will then affect the form design
process later. Instead of using it here, developer should take care of the
configuration of every control on each form individually. When later the
input mask on table level will be changed, the change may not be
populated to each and every form than. Even worse, if it nevertheless
might be populated, it may overwrite an already changed input mask on
form design.
Using the input mask on table design also prevents the developer to
input unexpected data on table level to test forms and reports properly.
9 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Input masks will also not be considered, for data coming from other
interfaces (such as imports from Excel, text files or other databases).
And so unexpected data might be imported into the database and must
be handled by forms and reports which may not be tested to work with
that data properly then.
Explanation
Also, only one (of possible several) relationships of a master to its child
tables can be shown here.
Explanation
10 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Explanation
For the above example, divide the two distinct tasks of cloning and
updating into two different statements.
Cloning
and updating
Explanation
MS Access clearly lists all stored queries inside one panel. With this
developers can keep track of all needed queries, their meaning and its
sight on the data in convenient way. This is an essential feature, when
changing the design of tables.
11 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Explanation
Buttons on forms may alter selection in a grid view even before VBA
code for buttons events are called. This occurs because the focus shifts
then from grid view to clicked button. Especially multi record selections
on subforms are cancelled, when button on mainform is clicked.
Explanation
Use distinct forms for adding new and manipulating existing record,
when datasheet or gridview is used for manipulation of records.
Explanation
12 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
visibility property via VBA. This way, GUI design and content is
separated by business logic.
Explanation
Queries task is to access the data layer and connect this to view layer.
When data layer will be altered (e.g. by adding new features to the
application), developers tend to first check the query layer for impacts
of that change. Change of VBA code, which relies on specific table
design, is harder to implement and developers may forget to update
rarely used VBA routines.
Exceptions
However, in rare cases there might be necessity for VBA code to directly
operate on tables. For example in case of backend update, VBA code (in
frontend) may alter the tables and their relationships directly.
Explanation
Forms and reports as well as their VBA code are hard to undergo
automated unit tests. Additionally, there are already frameworks to
13 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Explanation
By not using this option, the VBA developer does not need to declare
variables prior to their usage. This seems to be more comfortable at
first. But this prevents the compiler to automatically find mistyped
variables, which may result in very hard to find bugs.
Declaring a variable at first also defines its datatype and restricts the
usage of that variable to that datatype at the same time. So the
compiler also is able to find usage, which is not intended for that
variable. E.g. putting a surname into a long typed variable, which is
intended to take the age, will definitely arise problems when this
variable is checked for being greater than 21 later.
Explanation
When using DAO or ADO objects and methods, many objects and
methods are named the same. To guarantee unambiguity it is essential
14 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Explanation
15 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
Explanation
Although, MS Access Macros only can call VBA functions, instead of VBA
subroutines, the value returned by the VBA function will be ignored.
References
[1] RVBA Coding Conventions: http://www.xoc.net/standards
/rvbacc.asp
16 od 17 09.09.16 15:01
PrintWhatYouLike on Microsoft Access Application Development Gui... http://www.printwhatyoulike.com/print?url=http://www.codeproject.c...
This is why I have written this article from the experience of the MS
Access development I have done so far.
17 od 17 09.09.16 15:01