Default Values |
|
When you create a Microsoft Access database, to assist the person doing data entry, you can provide a value for a certain field so the user would not need to change it if not necessary. This is referred to as the default value. To be efficient, the default value should be the most commonly used value for that particular field. For example, when creating a table of employees that has a field called Country, since employees are most likely to reside in one country, you can provide the name of the country as the default value. To provide a default value, when creating the field in the Design View of the table (or form), you can access the Default Value property of the field and type the desired value. |
In some cases, you may want to provide a default value
but the value would depend on another value. For example, if you are
familiar with the system of telephone numbers in US and Canada, you may
know that telephone numbers are defined using the following
formula
Of course, there are other rules we will not care about at this time. Based on this, when the user enters a telephone number, you may want to provide a default value for the state or province. To do this:
The default value offered by Microsoft Access can be used only in the Default Value property of a field and can be specified in the Design View of the table or the form. If you want to use a conditional default value as we have done above, you would think of writing an expression either in the Default Value of the field in the table Design View or better, the Record Source of the field in the form's Design View. Unfortunately, Microsoft Access doesn't acknowledge this. This is why you have to use VBA. Even if you create a Text Box control and use it to hold the desired value. Once you write an expression in its Record Source or directly in one of its events in the Properties window, the user would not be allowed to enter any value in the field. This is one more reason VBA would be used. The main advantage of using VBA for a default value is that you can still let the user change the value of a field even if you had provided your suggestion through a default value. For example, if you create a table for employees and decide to let the user assign a username or an Email Address to employees, imagine you create an expression as a default value that uses the employees last name preceded by the first letter of his or her first name, there is still a chance that the company would have Jeannine Walter and Jimmy Walter in the database. While it is impossible to predict all possible scenarios, which is the reason most (if not all) companies employ a person in charge of assigning usernames and/or email address, you can provide preliminary code that can assist the user. Once your expression has been applied, the user can still change your suggestion if it doesn't fit or should not be accepted.
|
|
||
Home | Copyright © 2003-2007 FunctionX, Inc. | FunctionX |
|