Sunteți pe pagina 1din 8

Data types in Microsoft Access

Working with Database Fields Microsoft Access database fields are created by entering a field name and a field data type in each row of the field entry area of the database table window. The field description is an option to identify the fields purpose; it appears in the status bar during data entry. After you enter each field's name and data type, you can specify how each field is used by entering properties in the property area. Before you enter any properties, however, you should enter all of you fields names and data types. Naming a Database Field A field name identifies the field to both you and to Microsoft Access. For information regarding field names please see the article: Tables and Fields Specifying a Microsoft Access Data Type After you name a field, you must decide what type of data the field will hold. Before you begin entering data, you should have a grasp of the data types that your system will use. Ten basic data types are shown in the table below; some data types (such as numbers) have several options:
Microsoft Access Data Types

Data Type

Use For

Size

Text

Up to 255 characters. Microsoft Access only stores the characters Text or combinations of text and numbers, entered in a field; it does not store such as addresses. Also numbers that do not space characters for unused require calculations, such as phone positions in a Text field. To control numbers, part numbers, or postal codes. the maximum number of characters that can be entered, set the FieldSize property. Lengthy text and numbers, such as notes or Up to 64,000 characters. descriptions. Numeric data to be used for mathematical calculations, except calculations involving money (use Currency type). Set the FieldSize property to define the specific Number type. Dates and times. 1, 2, 4, or 8 bytes. 16 bytes for Replication ID (GUID) only. Click here for more information on changing Number field sizes. 8 bytes.

Memo

Number

Date/Time

Currency

Currency values. Use the Currency data type to prevent rounding off during calculations. 8 bytes. Accurate to 15 digits to the left of the decimal point and 4 digits to the right.

Unique sequential (incrementing by 1) or AutoNumber random numbers automatically inserted when a record is added. Yes/No

4 bytes. 16 bytes for Replication ID (GUID) only.

Fields that will contain only one of two 1 bit. values, such as Yes/No, True/False, On/Off. Objects (such as Microsoft Word documents, Microsoft Excel spreadsheets, pictures, sounds, or other binary data), created in other programs using the OLE protocol, that Up to 1 gigabyte (limited by disk can be linked to or embedded in a Microsoft space). Access table. You must use a bound object frame in a form or report to display the OLE object. Field that will store hyperlinks. A hyperlink can be a UNC path or a URL. Up to 64,000 characters.

OLE Object

Hyperlink

Lookup Wizard

Creates a field that allows you to choose a value from another table or from a list of The same size as the primary key values using a combo box. Choosing this field that is also the Lookup field; option in the data type list starts a wizard to typically 4 bytes define this for you.

The following list summarizes all the field data types available in Microsoft Access, their uses, and their storage sizes. Text Use for text or combinations of text and numbers, such as addresses, or for numbers that do not require calculations, such as phone numbers, part numbers, or postal codes. Stores up to 255 characters. The FieldSize property controls the maximum number of characters that can be entered. Memo Use for lengthy text and numbers, such as notes or descriptions. Stores up to 65,536 characters. Number Use for data to be included in mathematical calculations, except calculations involving money (use Currency type). Stores 1, 2, 4, or 8 bytes; stores 16 bytes for Replication ID (GUID). The FieldSize property defines the specific Number type. Date/Time Use for dates and times.

Stores 8 bytes. Currency Use for currency values and to prevent rounding off during calculations. Stores 8 bytes. AutoNumber Use for unique sequential (incrementing by 1) or random numbers that are automatically inserted when a record is added. Stores 4 bytes; stores 16 bytes for Replication ID (GUID). Yes/No Use for data that can be only one of two possible values, such as Yes/No, True/False, On/Off. Null values are not allowed. Stores 1 bit. OLE Object Use for OLE objects (such as Microsoft Word documents, Microsoft Excel spreadsheets, pictures, sounds, or other binary data) that were created in other programs using the OLE protocol. Stores up to 1 gigabyte (limited by disk space). Hyperlink Use for hyperlinks. A hyperlink can be a UNC path or a URL. Stores up to 64,000 characters.

Text. Essentially the same as the Character type in xBase. 255 character maximum. You can and should define a width, but Access doesn't use fixed width storage so is not as wasteful of disk space. Number. This category includes Byte (unsigned 8-bit), Integer (signed 16-bit), Long (signed 32bit), Single (signed 32-bit), and Double (signed 64-bit). Access XP introduces the Decimal (96bit fixed point, scaled), but there is no corresponding data type in VBA (so use Variant). Currency. A 64-bit fixed point number, designed to give the accuracy needed for financial data. 15 digits of whole dollars, plus four decimal places (hundredths of a cent). Counter. (Access 1 and 2 only.) A Long integer type, automatically assigned by Access. To look up a Counter in a one-to-many relationship, use a Long for the field type in the related table. Date/Time. Access stores Dates as 8-byte floating point numbers, where the integer part refers to the day, and the fraction part refers to the time. While Now() + 1/24 is theoretically

one hour from now, use the DateAdd() function to avoid rounding errors if you plan to use the result in comparisons. When constructing queries, keep in mind that if a Date/Time field contains a fraction part, it will not match a criteria which is just a date: Now() is not equivalent to Date(), though Int(Now()) is equivalent to Date(). Yes/No. A Logical field can be displayed as Yes/No, True/False, or On/Off. In code, use the constants True and False, equivalent to -1 and 0 respectively. Unfortunately, Access 95 onwards do not permit Null values in Yes/No fields. Memo. Similar to a Memo field in xBase. Up to 64K of text. Memos cannot include formatting (e.g. bolding a word). However, they are searchable. OLE Object. Use this type to store pictures, audio, video, or other BLOBs (Binary Large OBjects). Double-clicking fires up the associated application. Access 2 and later support inplace activation, e.g. WinWord documents can be stored and edited as OLE objects in a form (though Access will not be able to search them). Hyperlink. (Access 97 onwards.) Use this type to store the location of a file on your computer, a local network, or the world wide web. The field contains three parts separated by pound signs (#), with each part up to 2K in size. The first part is the text to be displayed, the second is the address of the file, and the third can reference a named section within the file. Example:

Create a Table from scratch in Design view


1. If you haven't already done so, switch to the Database Window You can press F11 to switch to the Database window from any other window.

2. Double-Click on "Create table in Design view". (DESIGN VIEW)

3. Define each of the fields in your table. o Under the Field Name column, enter the categories of your table. o Under Data Type column, enter the type you want for you categories. The attribute of a variable or field that determines what kind of data it can hold. For example, in a Microsoft Access database, the Text and Memo field data types allow the field to store either text or numbers, but the Number data type will allow the field to store numbers only. Number data type fields store numerical data that will be used in mathematical calculations. Use the Currency data type to display or calculate currency values. Other data types are Date/Time, Yes/No, Auto Number, and OLE object (Picture). o Under the Description column, enter the text that describes what you field is. (This field is optional). o For our tutorial enter the following items:

Back to top

Primary Key

One or more fields (columns) whose value or values uniquely identify each record in a table. A primary key does not allow Null values and must always have a unique value. A primary key is used to relate a table to foreign keys in other tables. NOTE: You do not have to define a primary key, but it's usually a good idea. If you don't define a primary key, Microsoft Access asks you if you would like to create one when you save the table. For our tutorial, make the Soc Sec # field the primary key, meaning that every student has a social security number and no 2 are the same. o To do this, simply select the Soc Sec # field and select the primary key button
o

After you do this, Save the table

Back to top

Forms
A form is nothing more than a graphical representation of a table. You can add, update, delete records in your table by using a form. NOTE: Although a form can be named different from a table, they both still manipulate the same information and the same exact data. Hence, if you change a record in a form, it will be changed in the table also. A form is very good to use when you have numerous fields in a table. This way you can see all the fields in one screen, whereas if you were in the table view (datasheet) you would have to keep scrolling to get the field you desire. Back to top

Create a Form using the Wizard


It is a very good idea to create a form using the wizard, unless you are an advanced user and know what you are doing. Microsoft Access does a very good job of creating a form using the wizard. The following steps are needed to create a basic form: 1. Switch to the Database Window. You can do this by pressing F11 on the keyboard. 2. Click on the Forms button under Objects on the left side of screen 3. Double click on Create Form Using Wizard

4. On the next screen select the fields you want to view on your form. Most of the time you would select all of them. 5. Click Next 6. Select the layout you wish 7. Click Next 8. Select the style you desire...HINT: if you plan on printing your form, I suggest you use a light background to save on printer toner and ink 9. Click Next 10. Give you form a name, and select Open the Form and enter information 11. Select Finish 12. You should see your form. To adjust the design of your form, simply hit the design button (same as with the tables), and adjust your form accordingly Back to top

Reports
A report is an effective way to present your data in a printed format. Because you have control over the size and appearance of everything on a report, you can display the information the way you want to see it. Back to top

Create a Report using the Wizard


As with the Form, it is a very good idea to create a report using the wizard, unless you are an advanced user. Microsoft Access does a very good job using the wizard to create reports. 1. Switch to the Database Window. You can do this by pressing F11 on the keyboard. 2. Click on the Reports button under Objects on the left side of screen 3. Double click on Create Report Using Wizard 4. On the next screen select the fields you want to view on your form. Most of the time you would select all of them. 5. Click Next 6. Select if you would like to group your files. Keep repeating this step for as many groupings as you would like. 7. Click Next 8. Select the layout and the paper orientation you desire 9. Click Next 10. Select the style you desire...HINT: if you plan on printing your report, I suggest you use a light background to save on printer toner and ink

11. Click Next 12. Give you report a name, and select Preview the Report 13. Select Finish 14. You should see your report. To adjust the design of your report, simply hit the design button (same as with the tables), and adjust your report accordingly

S-ar putea să vă placă și