This MSAccess tutorial explains how to create a query where the LIKE clause gets its condition from a text box in Access 2003 (with screenshots and step-by-step instructions). Show Question: In Microsoft Access 2003/XP/2000/97, how can I set up a query so that the LIKE clause gets its condition from a text box on my form? Answer: We'll demonstrate how to do this with the example below. In this example, we have a form called frmCustomers that has a text box called SearchValue. We've then set up a query that uses a LIKE condition whose condition comes from the SearchValue field on the frmCustomers form. As indicated by: Like [forms]![frmCustomers]![SearchValue] & "*" This query will return all records from the Customers table where the ContactTitle field starts with the value entered in the SearchValue field. So if "Manager of " was entered in the SearchValue field. The query would return all records from the Customers table where ContactTitle begins with "Manager of ". A string is text made of a readable letter, a symbol, a word or a group of words.Microsoft Access supports two broad types of text actually based on their length. A short text is one that has a maximum size of 255 characters. To support this, Microsoft Access provides a data type named Short Text. To specify that a column or field will use a short text:
To assist you with common text fields, Microsoft Access provides many options in the Datasheet View. To use one of them, on the Ribbon, click Fields, in the Add & Delete section, click More Fields. In the Quick Start section, click the desired option. If some columns exist already, to insert a text-based field between two columns, click the column header, or a cell under the column, that will precede it. On the Ribbon, click Fields. If a column has been created already and it is using a data type other than Short Text, to change it, click its column header or a cell under its column. On the Ribbon, click Fields. In the Formatting section, click the arrow of the Data Type combo box and select Short Text. Practical Learning: Introducing Strings
Text on a Form As we have seen in previous lessons, after creating text-based field, you can add it to a form or report, in which case it would be used as a text box. A text-based column can also be used in a form or report as a combo box or any text-based control. To access the string stored in a text box or any text-based control, use only the name of the control (don't add .Text) Practical Learning: Using Text on Windows Controls
Text as a Value To indicate or specify the value of a string, put it between double-quotes. Introduction to Strings and Expressions As mentioned in the previous lesson, you can create an expression-based column on a table. The expression can include only constant values, only constant strings, only columns names, or a combination of those. Practical Learning: Creating and Using Text-Based Expressions
Primary Charactistics of Strings The Size of a String The size of a string is the number of characters it contains or may hold. By default, when you have just created a Short Text-based field, whether in the Datasheet View or Design View, its default size is automatically set to 255 characters. In some circumstances, you may want the field to deal with a different size. You can therefore decrease or increase this size for any number between 1 and 255: To specify the allowable number of characters of a Short Text-based field:
As mentioned already, the default size of a Short Text-based field is set to 255. This value is set in the Access Options. To change it, open the dialog box (on the Ribbon, click File and click Options). In the Default Text Field Size spin button, enter the desired value: After setting the Field Size property, the database would make sure that the user can only type so many characters. Practical Learning: Setting Field Sizes
The Length of a String To get the size of a string, you can call a function named Len. Its syntax is: Len(String) As Number When calling this function, pass a string etween double-quotes or the name of a control. The function then produces the number of characters in it. Practical Learning: Setting the Maximum Size of a Short Text Field
Input Masks A mask is a technique of creating sections, also called placeholders, in a field. A section can be configured to accept only a letter, only a digit, a character or a digit, any symbol, nothing, or a particular character that the user cannot change. Microsoft Access supports two primary categories of masks: implicit and explicit. An implicit mask is one that is comtrolled by a data type. This means that, if you set a certain data type to a field, Microsoft Access can make sure that only valid values can be entered into the field. An explicit mask is a field that is made to control what value is entered into it. When creating the mask, you will use some predefined characters and create a combination of your choice. A mask, or the type of mask, depends on the data type of the field. You can create the mast for a field of a table or for a text box in a form. If you create the mask for a field in a table, when that field is added to a form, the mask will apply. If you change the mask of an existing field of a table after that field has been added to a form, the text box of that field will not be update on the form. You can either delete the text box on the form and re-add it to the form, or you can create the mask on the form. To create a(n explicit) mask on a field:
In both cases, the field will be equipped with a browse button:. Before creating a mask for a field, Microsoft Access comes with various pre-defind masks you can apply to a field. Masks are available for dates, times, US Social Security Number, currency values, etc. To help you apply one of these masks, Microsoft Access is equipped with the Input Mask Wizard. To open it, click the Browse button. The first page of the wizard displays the most regularly used masks, including those for US/Canada telephone number, US Social Security #, US ZIP code, date, time, etc: If you see a mask that suits you, you can check it by clicking the Try It text box. This would show the placeholders for the sections of characters that could be entered during data entry. If you see a mask you want to use, you can click it and click Next. If none of the masks suits your need, you can create a new one and add it to the list. To do this, click the Edit List button. This would open the Customize Input Mask Wizard dialog box: By default, the Customize Input Mask Wizard offers four already created masks, including US/Canada phone number, US Social Security Number, US ZIP Code, and telephone extension number. You can check them by click the Next Record buttonin the bottom section of the dialog box. To create a new mask, click the New (Blank) Record button. After creating a new mask, you can click Close. To complete the mask, continue with the wizard. If none of the masks provided by the wizard suits you, you can create your own. To do that, click the Input Mask property for the desired fields and uses the following characters to create the mask: CharacterUsed to enter or accept0A single digit9A single digit or space#A digit, space, + or -LAn alphabetical character?A letterAA letter or a digitaA letter, a digit, or nothing&A character or spaceCA character, space, or nothing.A decimal place holder; for US English, this would be the period,Thousand separator; for US English, this would be a comma:;-/Date and time separator, as specified in the Regional Settings of Control Panel<A letter; the letter will be converted to lowercase>A letter; the letter will be converted to uppercase!Anything; the mask is filled from right to left for this position|Anything; the character that follows this one will be displayed itself. For example, if you type |L, the letter L would be displayed instead of being used a mask If you want to include a word or sentence as part of the mask, type it in any section as desired. Practical Learning: Using Input Masks
SQL and Strings The SQL supports strings in two data types: CHAR, TEXT, and VARCHAR. They are the same as Microsoft Access's Short Text data type. Here are examples of using them: CREATE TABLE Contractors ( FirstName CHAR, LastName TEXT, Gender CARCHAR ); The char or the text data types are used for columns whose fields would receive (or present) text of 1 to 255 characters. If you want the field to hold a maximum of less than 255 characters, you must add parentheses to the data type and enter the maximum number in the parentheses. Here are examples: What is a combo box Access?Combo box The combo box control provides a more compact way to present a list of choices; the list is hidden until you click the drop-down arrow. A combo box also gives you the ability to enter a value that is not in the list. In this way, the combo box control combines the features of a text box and a list box.
What is the use of text box in the form?A text box is an object you can add to your document that lets you put and type text anywhere in your file. Text boxes can be useful for drawing attention to specific text and can also be helpful when you need to move text around in your document.
What is a navigation form?A navigation form is simply a form that contains a Navigation Control. Navigation forms are a great addition to any desktop database. Microsoft Access offers several features for controlling how users navigate the database.
What is a label control in Access?A label is a control that holds text for display purposes only. By default, MS Access adds a label containing the table name in the Form Header area of the form. To add a label you must click the Label control, then click (and drag for sizing) where you want the label placed.
|