Vous êtes sur la page 1sur 9

Create a database with name of employee and add below fields in your database

Database name:- employee


Table name:- emp

Now open your project and press “Ctrl + T” to add two components Ado and Masked Edit Control
Select these two options from the list

add some fields, seven text fields, nine labels, two combo box, two option buttons, nine command buttons, two frames and
two Masked box fallow the below image.

Here is a trick that I have add two masked box behind two fields you can see them in below image. and you will also repeat
this trick
Your masked edit box should be hide ok

Now before to do anything you change the name for each field, which I have done in below image
txtName txt_d_o_j
txt_address
txtNo txt_tel_no Text1

txt_d_o_b
txt_course_id Text2
txt_faculty_id
txt_age cmdSearch
cmdSave cmdDelete cmdUpdate

cmdFirst
cmdNext
cmdLast
cmdPrevious
Now go to code window and write this code on the top

Dim adoconn As New ADODB.Connection


Dim rs As New ADODB.Recordset

After that, double click on the form and write this code.

Private Sub Form_Load()


Dim str As String
Me.Caption = "Company Database"
Set adoconn = Nothing
adoconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=employee.mdb;Persist Security Info=False"
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
rs.MoveFirst
txtNo.Text = rs(0)
txtName.Text = rs(1)
txt_address.Text = rs(2)
txt_age.Text = rs(3)
txt_course_id.Text = rs(4)
Text1.Text = rs(5)
txt_tel_no.Text = rs(6)
Text2.Text = rs(7)
txt_faculty_id.Text = rs(8)
End Sub

Double click on save button and write this code

Private Sub cmdSave_Click()


rs(0) = txtNo.Text
rs(1) = txtName.Text
rs(2) = txt_address.Text
rs(3) = txt_age.Text
rs(4) = txt_course_id.Text
rs(5) = txt_d_o_j.Text
rs(6) = txt_tel_no.Text
rs(7) = txt_d_o_b.Text
rs(8) = txt_faculty_id.Text
rs(9) = Opt1_male.Caption
rs(9) = Opt2_female.Caption
rs.Update
MsgBox "The record has been saved successfully.", , "ADD"
cmdFirst.Enabled = True
cmdLast.Enabled = True
cmdNext.Enabled = True
cmdPrevious.Enabled = True
cmdDelete.Enabled = True
cmdSearch.Enabled = True
cmdUpdate.Enabled = True
cmdSave.Visible = False
cmdAdd.Visible = True
Text1.Visible = True
Text2.Visible = True
End Sub
For delete button

Private Sub cmdDelete_Click()


Dim ans As String, str As String
ans = MsgBox("Do you really want to delete the current record?", vbExclamation + vbYesNo, "DELETE")
If ans = vbYes Then
adoconn.Execute ("delete from emp where std_no=" & txtNo.Text)
MsgBox ("The record has been deleted successfully.")
Set rs = Nothing
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
rs.MoveFirst
txtNo.Text = rs(0)
txtName.Text = rs(1)
txt_address.Text = rs(2)
txt_age.Text = rs(3)
txt_course_id.Text = rs(4)
txt_d_o_j.Text = rs(5)
txt_tel_no.Text = rs(6)
txt_d_o_b.Text = rs(7)
txt_faculty_id.Text = rs(8)
End If
End Sub

For update button

Private Sub cmdUpdate_Click()


Dim ans As String
ans = MsgBox("Do you really want to modify the current record?", vbExclamation + vbYesNo, "DELETE")
If ans = vbYes Then
rs.Update

cmdFirst.Enabled = False
cmdLast.Enabled = False
cmdNext.Enabled = False
cmdPrevious.Enabled = False
cmdDelete.Enabled = False
cmdSearch.Enabled = False
cmdUpdate.Enabled = False
cmdSave.Visible = True
cmdAdd.Visible = False
End If
End Sub

For search button


Private Sub cmdSearch_Click()
Dim key As Integer, str As String
key = InputBox("Enter the Student No whose details u want to know: ")
Set rs = Nothing
str = "select * from emp where std_no=" & key
rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly
txtNo.Text = rs(0)
txtName.Text = rs(1)
txt_address.Text = rs(2)
txt_age.Text = rs(3)
txt_course_id.Text = rs(4)
txt_d_o_j.Text = rs(5)
txt_tel_no.Text = rs(6)
txt_d_o_b.Text = rs(7)
txt_faculty_id.Text = rs(8)
Set rs = Nothing
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
End Sub

For cmdfirst button


Private Sub cmdFirst_Click()
rs.MoveFirst
txtNo.Text = rs(0)
txtName.Text = rs(1)
txt_address.Text = rs(2)
txt_age.Text = rs(3)
txt_course_id.Text = rs(4)
Text1.Text = rs(5)
txt_tel_no.Text = rs(6)
Text2.Text = rs(7)
txt_faculty_id.Text = rs(8)
End Sub

For cmdlast button


Private Sub cmdLast_Click()
rs.MoveLast
txtNo.Text = rs(0)
txtName.Text = rs(1)
txt_address.Text = rs(2)
txt_age.Text = rs(3)
txt_course_id.Text = rs(4)
Text1.Text = rs(5)
txt_tel_no.Text = rs(6)
Text2.Text = rs(7)
txt_faculty_id.Text = rs(8)
End Sub

For cmdnext button


Private Sub cmdNext_Click()
rs.MovePrevious
If rs.BOF = True Then
MsgBox "This is the first record.", vbExclamation, "Note it..."
rs.MoveFirst
End If
txtNo.Text = rs(0)
txtName.Text = rs(1)
txt_address.Text = rs(2)
txt_age.Text = rs(3)
txt_course_id.Text = rs(4)
Text1.Text = rs(5)
txt_tel_no.Text = rs(6)
Text2.Text = rs(7)
txt_faculty_id.Text = rs(8)
End Sub

For cmd previous button


Private Sub cmdPrevious_Click()
rs.MoveNext
If rs.EOF = True Then
MsgBox "This is the last record.", vbExclamation, "Note it..."
rs.MoveLast
End If
txtNo.Text = rs(0)
txtName.Text = rs(1)
txt_address.Text = rs(2)
txt_age.Text = rs(3)
txt_course_id.Text = rs(4)
Text1.Text = rs(5)
txt_tel_no.Text = rs(6)
Text2.Text = rs(7)
txt_faculty_id.Text = rs(8)
End Sub

Author Name:- Abdulwahab


Email:- itspot@hotmail.com

Vous aimerez peut-être aussi