10. Write a VB Program to accept the details of employees from user & store details in to the database. Display those details onto the screen by using report. (Use Standard ADODC controls.) Employee details contain empcode, empname, salary, address.


Dim C As New Connection
Dim R As New Recordset
Dim S As String
Private Sub cmdAdd_Click()
txtEmpCode.Text = “”
txtEmpName.Text = “”
txtEmpAddr.Text = “”
txtSal.Text = “”

txtEmpCode.SetFocus
End Sub
Private Sub cmdNext_Click()
R.MoveNext
If Not R.EOF Then

txtEmpCode.Text = R.Fields(0).Value
txtEmpName.Text = R.Fields(1).Value
txtEmpAddr.Text = R.Fields(2).Value
txtSal.Text = R.Fields(3).Value
Else
MsgBox “No More Records!”, vbInformation, “Employee”
End If
End Sub
Private Sub cmdPrev_Click()
R.MovePrevious
If Not R.BOF Then
txtEmpCode.Text = R.Fields(0).Value
txtEmpName.Text = R.Fields(1).Value
txtEmpAddr.Text = R.Fields(2).Value
txtSal.Text = R.Fields(3).Value
Else
MsgBox “No More Records!”, vbInformation, “Employee”
End If
End Sub
Private Sub cmdSave_Click()
R.Close
S = “Insert Into tblEmp Values(” & Val(txtEmpCode.Text) & “,'” & txtEmpName.Text & “‘,'” & txtEmpAddr.Text & “‘, ” & Val(txtSal.Text) & “)”
R.Open S, C, adOpenDynamic, adLockOptimistic
S = “Select * From tblEmp”
R.Open S, C, adOpenDynamic, adLockOptimistic
If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtEmpCode.Text = R.Fields(0).Value
txtEmpName.Text = R.Fields(1).Value
txtEmpAddr.Text = R.Fields(2).Value
txtSal.Text = R.Fields(3).Value
End If
MsgBox “Employee Added Successfully!”, vbInformation, “Employee”

End Sub

Private Sub Command1_Click()
DataReport1.Show
End Sub

Private Sub Command2_Click()
Unolad Me
End Sub

Private Sub Form_Load()
S = “Select * From tblEmp”
C.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VBSlipSol\Slip10\Ques-2\emp.mdb;Persist Security Info=False”
R.Open S, C, adOpenDynamic, adLockOptimistic

If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtEmpCode.Text = R.Fields(0).Value
txtEmpName.Text = R.Fields(1).Value
txtEmpAddr.Text = R.Fields(2).Value
txtSal.Text = R.Fields(3).Value
End If
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s