Times of India Tech: Latest IT, telecom, Internet, BPO news and updates

Sunday, March 31, 2013

Functions - Category


MS Access: Functions - Category

Below is a list of the most commonly used functions in Access. These functions can generally be used in either VBA code or SQL/Queries.

Functions - Alphabetical


S Access: Functions - Alphabetical

Below is a list of the most commonly used functions in Microsoft Access. These functions can generally be used in either VBA code or SQL/Queries.

Naming Variables (Programming Standards)


MS Access: Naming Variables (Programming Standards)

We try to prefix all variables with a letter indicating the scope of the variable. This makes it easier to figure out where the variable has been declared.
Here is a quick summary of the naming conventions that we use:
ScopeExampleExplanation
GlobalGClient_IDAll global variables should be prefixed with "G".
LocalLClient_IDAll local variables should be prefixed with "L".
ParameterpClient_IDAll parameters should be prefixed with "p".

Global Variables

What is a Global variable?
A Global variable is one that can be accessed from anywhere in your program. We try to prefix all Global variables with "G".
Microsoft Access
For example, you could create a global variable called GClient_ID with the following command:
Global GClient_ID As Integer
Global variables are generally declared at the top (ie: Declarations section) of a module.

Local Variables

What is a Local variable?
A Local variable is one that exists only within the current function or subroutine. We try to prefix all Local variables with "L".
For example, you could create a local variable called LTotalDays with the following command:
Dim LTotalDays As Integer
Local variables are generally declared at the top (ie: Declarations section) of a function or subroutine.
Below is an example of a function:
Function Example1() As Integer

   Dim LTotalDays As Integer
   Dim LSaturdays As Integer
   Dim LSundays As Integer
   
   LTotalDays = DateDiff("d", StartDate, EndDate)
   LSaturdays = DateDiff("ww", StartDate, EndDate, 7)
   LSundays = DateDiff("ww", StartDate, EndDate, 1)
   
   'Elapsed days excluding Saturdays and Sundays
   Example1 = LTotalDays - LSaturdays - LSundays
   
End Function
In this example, we've created three local variables - LTotalDays, LSaturdays, and LSundays.

Parameters

What is a Parameter?
A Parameter is a variable that is used to pass information to or from a function or subroutine. We try to prefix all parameters with "p".
For example, we could create parameters in a function as follows:
Function Example2(pStartDate As Date, pEndDate As Date) As Integer

   Dim LTotalDays As Integer
   Dim LSaturdays As Integer
   Dim LSundays As Integer
   
   LTotalDays = DateDiff("d", pStartDate, pEndDate)
   LSaturdays = DateDiff("ww", pStartDate, pEndDate, 7)
   LSundays = DateDiff("ww", pStartDate, pEndDate, 1)
   
   'Elapsed days excluding Saturdays and Sundays
   Example2 = LTotalDays - LSaturdays - LSundays
   
End Function
In this example, we've created a function with two parameters - pStartDate and pEndDate.
You could also create parameters in a subroutine as follows:
Sub Example3(pStartDate As Date, pEndDate As Date)

   Dim LTotalDays As Integer
   
   LTotalDays = DateDiff("d", pStartDate, pEndDate)
   
   'Elapsed days
   MsgBox "There are " & LTotalDays & " elapsed days."
   
End Sub
In this example, we've created a subroutine with two parameters - pStartDate and pEndDate.

Setting up Tables and Naming Fields (Programming Standards)


MS Access: Setting up Tables and Naming Fields (Programming Standards)

Here are a few of the programming standards that we try to follow when setting up tables and defining fields within those tables.

Setting up Tables

Guideline #1: Create tables with meaningful names. For example, if you want to create a table that stored information about your suppliers, then name the table Suppliers.
Microsoft Access
Guideline #2: Even though Access allows spaces in your table names, you may want to consider using the underscore character ("_") instead of a space. This will make it easier for you in the long run if you decide to port your tables to a different database. Most other databases do not allow spaces in table names.
For example, if you wanted to create a table that stored your order details, instead of calling the table Order Details, you might want to consider naming the table Order_Details.
Microsoft Access
Guideline #3: Use only alphanumeric characters when naming your tables. Do not use characters such as colons, semi-colons, brackets, etc.
Guideline #4: Try to create a primary key on your tables. A primary key is what uniquely defines each record in a table. If you do not have a combination of fields in your table that uniquely defines a record, then consider creating an AutoNumber field that acts as your primary key.
In the example below, we've created an AutoNumber field called Supplier_ID that acts as a primary key in our Suppliers table.
Microsoft Access

Naming Fields

The programming standards that we use for naming fields are very similar to those for naming tables.
Guideline #1: Create field names that are meaningful. Do not name your field names - Field1, Field2, Field3, etc., but choose names that identify what kind of information will be stored in the fields.
Guideline #2: Even though Access allows spaces in your field names, you may want to consider using the underscore character ("_") instead of a space. This will make it easier for you in the long run if you decide to port your tables to a different database. Most other databases do not allow spaces in field names.
For example, if you wanted to set up a field that stored the company name, instead of calling the field Company Name, you might want to consider naming the field Company_Name.
Microsoft Access
Guideline #3: Use only alphanumeric characters when naming your fields. Do not use characters such as colons, sem-colons, brackets, etc.

Shortcut Keys for Entering Data in a Datasheet/Form


MS Access: Shortcut Keys for Entering Data in a Datasheet/Form

The following is a list of shortcuts or hot keys for entering data in a Datasheet/Form:
Key SequenceDescription
CTRL+PLUS SIGN (+)Add a new record.
CTRL+MINUS SIGN (-)Delete the current record.
CTRL+SEMICOLON (;)Insert the current date.
CTRL+COLON (:)Insert the current time.
CTRL+ALT+SPACEBARInsert the default value for the field.
CTRL+ENTERInsert a new line.
SHIFT+ENTERSave changes to the current record.
SPACEBARToggle between the values in a check box or radio button.

Shortcut Keys for Working with Text/Data


MS Access: Shortcut Keys for Working with Text/Data

The following is a list of shortcuts or hot keys for working with text/data in Access:

General

Key SequenceDescription
F7Check spelling.
CTRL+CCopy the selection to the Clipboard.
CTRL+VPaste the contents of the Clipboard to where the insertion point is.
CTRL+XCut the selection and copy it to the Clipboard.
CTRL+ZUndo typing.
CTRL+DELETEDelete all characters to the right of the insertion point.
CTRL+SEMICOLON (;)Insert the current date.
CTRL+COLON (:)Insert the current time.
CTRL+ALT+SPACEBARInsert the default value for the field.
ESCUndo changes in the current field. Press ESC a second time to undo changes to the current record.
SHIFT+F2Open the Zoom box to enter large amounts of data that can not be properly displayed in a small control.

Finding and replacing text

Key SequenceDescription
CTRL+FOpen the Find tab on the Find and Replace dialog box.
CTRL+HOpen the Replace tab on the Find and Replace dialog box.
SHIFT+F4Find the next occurrence of the value entered in the Find and Replace dialog box when the dialog box is closed.

Selecting text in a field

Key SequenceDescription
SHIFT+RIGHT ARROWExtends selection one character to the right.
SHIFT+LEFT ARROWExtends selection one character to the left.
CTRL+SHIFT+RIGHT ARROWExtends selection one word to the right.
CTRL+SHIFT+LEFT ARROWExtends selection one word to the left.

Moving the insertion point in a field

Key SequenceDescription
RIGHT ARROWMove one character to the right.
LEFT ARROWMove one character to the left.
CTRL+RIGHT ARROWMove one word to the right.
CTRL+LEFT ARROWMove one word to the left.
ENDMove to the end of the field, in a single-line field.
HOMEMove to the beginning of the field, in a single-line field.
CTRL+ENDMove to the end of the field, in a multi-line field.
CTRL+HOMEMove to the beginning of the field, in a multi-line field.

General Shortcut Keys


MS Access: General Shortcut Keys

The following is a list of general shortcuts or hot keys in Access:
Key SequenceDescription
F1Display the Microsoft Access Help.
This may be context-sensitive help depending on what you are positioned on.
F11Display the Database window.
F12Open the Save As dialog box.
CTRL+NOpen a new database.
CTRL+OOpen an existing database.
CTRL+PPrint the current or selected object.
CTRL+SSave the current database object.
CTRL+WClose the active window.
ALT+SPACEBARDisplay the Control menu.
ALT+F11Toggle between the Visual Basic editor and the Access Database window.
SHIFT+F10Display the shortcut menu (ie: popup menu).

MS Access: Date/Time


MS Access: Date/Time

Tables

Queries

Forms/Subforms

Reports

Formatting

Miscellaneous

Switchboard


MS Access: Switchboard

switchboard is a form that allows you to navigate around your Access database. The switchboard is made of buttons that you click. You can program these buttons to open forms, reports, queries, etc.
Microsoft provides a switchboard wizard that allows you to define the look and feel of your switchboard.

Basics