1
Introduction to Computing
January-20-2013
Microsoft Ms Access/to
option
something./application
MS ACCESS. IT IS THE TOOLS OF MICROSOFT OFFICE
WHICH IS USED FOR DATABASES.
DOCTOR MATRON IN 1981 DEFINE DATABASE.
DATABASE . IT IS SHARE COLLECTION ENTER RELATED
DESIGN TO MEET THE NEED OF MULTIPLE TYPE OF ANY
USER.
Data
The collection of facts and figures is called data
Base
The place where we store the data is called base.
ID Name Post Address Email Phone Qualification
1 Omid Doctor Kabul Gmail 07011 BBA
2 Jan Eng Mazar FB 07011 BCS
3 Khan IT Herat Mee 07011 BIT
4 Walid HR Logar FB 07011 BSC
5 Ramin Admin Bamian Tag 07011 MBA
6 Yama Assi Mazar Hot 07011 MDB
7 Jamal IT Logar Yaho 07011 MCI
Database
Those programs which consist of Four objects as tables, queries, form
and report is called database.
Or
Those programs in which we are able to search record levels is called
database.
Table
The collection of rows and columns is called table.
Table is the basic storage unite all the records can be stored in table.
If there is no table there will be no query, no forms or reports.
Before 1970s
In the old days, before 1970s, there was no database software, people
using the File System. File system generates the ASCII ( American
Standard Codes for Information Interchange ) Data Files, which was
unsecure and can be affected very soon, in 1970s, different
companies, IBM, ORACLE, Ashton Tate, developed the database
management Systems, Ashton Tate introduce first Micro computers
Database Management System called dBase.
Later, Microsoft in 1989, developed the Microsoft windows, and also
developed Microsoft Office Package, and introduce a component of
Microsoft Office called Microsoft Access Program.
input mask
we have two main things in input mask as following
(1) Mandatory
when it is mandatory so the entry in field will be according to the
setting neither more nor less that setting.
example if in any filed we write text then mandatory is capital L and
capital A
if in any field we write number then for that field mandatory is o
(2) Optional
when it is optional so we can enter less than setting but no more than
that setting
if we write number in any filed for that field optional is 9 and the field in
which we write text for that field optional is small a and ? mark
Text Properties (Input mask)
1. AAAA (for both number and text only four characters neither less
nor more)
2. LLLL (for only text only four characters nether less nor more)
3. aaaa ( for both number and text but not more than four
characters but you can enter less four characters)
4. ???? ( only for text but not more than four characters but you can
enter less than four characters)
5. >?<???????????????????? ? (for first letter automatic capital )
6. (it is 0000 only for numbers but only four characters neither more
nor less)
7. 9999 (it is only for numbers you enter until four characters not more
but you can enter less than four characters)
8. Password (it shows your text like password)
Text Properties (Validation Rule)
1. In ("omid","jan","khan") (it means we only enter these names not
without them)
2. Like a* (it means we can enter only those names which are started by
a)
3. Like *a (it means we can enter only those names which ended by a)
4. Like a*d ( it means we can enter only those names which started by a
and ended by d)
5. <h (it means we enter those names which names are started by a, b,
c , d, f, g)
6. >w (it means we enter those name which name are started by w, x, y,
z)
7. Like "[a-f]*" (it means we enter those names which name are started by
a until f (a,b,c,d,e,f)
8. Is not null ( it means we cannot leave empty cell)
9. Is null (it means we cannot fill this record it should be empty)
10. =omid (it means we only enter this name (omid) nothing else)
Number Properties (Field size)
1. Byte = 255 Digits
2. Integer = 32767 Digits
3. Long integer = until nine numbers not more but it can not
accept the decimal.(9)
4. Single = until seven (7) numbers with decimal.
5. Double = until 11 numbers with decimal. In access 2007 and
2010 but 2013 until (15) characters with decimal.
6. Replication ID= It remove a column permanently. We can not
bring it back.
7. Decimal = until 11 numbers without decimal. In access
2007 and 2010 (18) characters without decimal.
Number Properties (Format)
1. "af,"# ( it is for Currency)
2. "af,"# [red] (it mean Currency with color)
3. "af,"#,### and Cama (format for Currency)
4. # "af" (it means first money then currency)
5. #[Red] (it is only for text color)
6. #" salary" ( salary is here message you can write any
message here)
Number Properties (Input Mask)
1. AAAA or 0000 ( It meant nether more not less than four
digits)
2. aaaa or 9999 ( It meant not more than four digits but
you can write less than four c digits)
3. 0000" - "00" - "00" - "00" -” or \ (0000") - "00" - "00" -
"00 for fixing mobile numbers.
Number Properties (Validation Rule)
1. =400 (it mean only 400 nether less nor more)
2. >= 400 (it means more than 400 and include 400)
3. <=4000 (it means less than 400 and include 400)
4. Between 100 And 500 (it means salary must be between 100 until
500 neither more nor less)
5. In (100,200,300) (it means only enter 100, 200, 300 not any more)
6. Not In (100,200,300) (it means you cannot enter 100, 200, but you
can enter others
7. <> 10000 it means do not accept 10000.
Date/Time Properties (Validation Rule)
1. >1/11/2010 (it means we only enter that means we only enter after the mention time
not before)
2. <1/11/2010 ( it means we only enter before the mention time not after)
3. like *08 ( it means we can only enter the date in 2008 nether after no less)
4. Not like *08 ( it means we can only enter the date in before 2008 and after 2008 not in
2008)
5. in (#1/2/2010#,#5/2/2010#,#9/2/2010#) ( it means we can enter the exact mention
date nether less non more)
6. Not In (#1/2/2010#,#5/2/2010#,#9/2/2010#) (it means we cannot enter the exact
mention date nether less non more)
7. Between #01/01/2008# and #01/20/2008# (it means we can enter the date between
mention date neither more nor less)
8. Not Between #01/01/2008# and #01/20/2008# (it means we cannot enter the date
between mention date)
9. <>#01/01/2010 or Not = 01/01/2010 (it means we cannot enter the date between
mention date but it is only for one day)
10. =1/11/2010 (it means we only enter that mention time nether less non-more)
Relationship
Relationship means to restrict invalid data against
database.
Relationship types are as following
(1) one to one
when there is primary key on both of relating tables is
called one to one
(2) one to many
when there is primary key on one table but no primary
key on another table is called one to many.
(3) many to many
when data comes from multiple tables to one table and
from that table data goes to multiple tables is called many
to many
Rules for Relationship
(1) Primary key is must if it is on one or more than
one table.
(2) there will be no data in child table before relating
tables.
(3) we must have a plan making Relationship.
(4) number to number possible, number to autonumber
possible, text to text possible autonumber to autonumber
is not possible.
we have two kinds of table
1. Master or main table
the table which has primary key
2. child or sub table.
the table which has no primary key
Query:
A query is simply a question represented in a way that Access
can understand. It is a basic tool that Access provides for
retrieving information from your database. It allows you to
take information from single or multiple tables in order to
obtain the data you want. Each query functions like a
question that can be asked immediately or saved to be asked
later. Although this question will generally remain unchanged,
the altering nature of database means that the answer
access provides will generally be different each time the
query is run
Combine the table
Create the second table
Click on query command
From dialog box select the both tables and click on “OK”
Now you can see we have two table to combine
Drag and drop the Fields and make the new table
Creating searching table
Open the query and add fields on Field area
Click on criteria row and select the field that you want to
make a searching on it
Open a bracket and write something into it like: [Enter your
name]
Save the table
Open the searching query and write the name on it.
Make table
1. first add table from dialog box
2. Add field such as (id, name, salary….)
3. go to the new column
4. Type percentage: [Salary]+[Salary]*10/100
5. click on make table and in table name box, type “percentage”
6. then save the query by the name of make table
7.click on make table now you can see, this command have created the
percentage table
Append table
1. Repeat the step 1,2
2. click on Append table command the dialog box will appear
3. From dialog box select the “table” like Employee
4. Click on “Ok”
5. Save the Append Query by the name of Append table
6. click on Append table you can see, you have Appended the employee table
7. open the employee table
Update
1. add fields
2. click on update command
3. go to the Update to field
4. open a bracket on name column and enter the following code [Enter the new
employee name]
5. click on Criteria field and enter the following code [Enter the old employee
name]
6. save the update query by the name of update the employee name
7. click on update employee name query
8. enter the new employee name on first dialog box
9. Enter the old employee name on second dialog box
Functions for Salary
Present_Day:
abs([1st]+[2nd]+[3rd]+[4th]+[5th]+[6th]+[7th]+[8th]+[9th]+[10th]+[11t
h]+[12th]+[13th]+[14th]+[15th]+[16th]+[17th]+[18th]+[19th]+[20th]+[2
1th]+[22th]+[23th]+[24th]+[25th]+[26th]+[27th]+[28th]+[29th]+[30th])
Absent_days: 30-[Present_day]
Oneday-Salary: [salary]/30
AbsentdaySalary: [Oneday-salary]*[Absent_days]
Net_salary: [Salary]-[AbsentdaySalary]
Attendance and finance functions
Absent_days: 30-[Present_day]
Oneday-Salary: [salary]/30
AbsentdaySalary: [Oneday-salary]*[Absent_days]
Net_salary: [Salary]-[AbsentdaySalary]
Structure Query language
Select * from Employee
Select name from Employee
Select Job from Employee
Select name from Employee where name=“Fahim”;
Select job from Employee where job=“Manager”;
Select salary from Employee where salary>2000;
Private Sub Clear_Click()
Result = ""
no1 = "" Topic: Creating Calculator
no2 = ""
End Sub
Private Sub Divide_Click()
Result = (no1) / (no2)
End Sub
Private Sub Minus_Click()
Result = (no1) - (no2)
End Sub
Private Sub Multiply_Click()
Result = (no1) * (no2)
End Sub
Private Sub Pluse_Click()
Result = Val(no1) + Val(no2)
End Sub
Variable coding
What is a Variable?
It is a memory location where we store the data
How to define a variable?
By the word Dim the variable is defined to memory
How to write the name of variable?
The name of variable could be any thing but you should use the
letters not numbers or symbols
How to create the relationship of variable with datatype?
The word “as” is used to show the datatype and “String” is a
variable which accept the letters and numbers
Topic: Creating Searching via Variable
Variable coding
Create a form
Add fields and use a button
Code builder
Dim a As string
a = InputBox (“Please type the EmpID”)
DoCmd.ApplyFilter , “ID=“ & a
Topic: Changing Caption of button
Variable coding
Dim a as string
a = inputBox (“enter our country name”)
If a =“Afghanistan” then
Me. Command20.caption =“Kabul”
Elseif a=“Iran” then
Me. Command20.caption =“Tehran”
Elseif a = “USA” then
Me.command20.caption = “Washington D.C”
Else
a = MsgBox(“Sorry it is not a country name”)
End If
Dim no1 As String
Variable coding
Dim no2 As String
Dim c As String
no1 = InputBox("Please enter the first value")
no2 = InputBox("Please enter the scond value")
c = InputBox("Enter your operator sign")
If c = "+" Then
MsgBox (no1 + no2)
Elseif c = "-" Then
MsgBox (no1 - no2)
Elseif c = "*" Then
MsgBox (no1 * no2)
Elseif c = "/" Then
MsgBox (no1 / no2)
End If
Option group Coding
Private Sub Frame17_BeforeUpdate(Cancel As Integer)
If Frame17.Value = 1 Then
Me.Bonus.Value = Me.salary * 10 / 100
ElseIf Frame17.Value = 2 Then
Me.Bonus.Value = Me.salary * 20 / 100
ElseIf Frame17.Value = 3 Then
Me.Bonus.Value = Me.salary * 30 / 100
End If
End Sub
Variable coding
If frame 17=1 then
Docmd.openform “BCS”
Elseif frame17=2 then
Docmd.openform “BBA”
End if