Skip to main content

Write a VB program to search an employee record from the database according to the empcode and display that record onto the form. (Use input box).

· One min read
Kaustubh Kulkarni
Dim c As New Connection  
Dim r As New Recordset
Dim sql As String

Private Sub cmdSearch_Click()
Dim id As Integer
id = Val(inputBox("enter number to search"))
sql = "select * from emp where empcode like '" & id & "'"
r.Opensql, c, adOpenDynamic, adLockPessimistic
If Not r.EOF And Not r.BOFThen
Call display
MsgBox ("No record Found")
End If

End Sub
Private Sub Form_Load()
sql = "select * from emp"
c.Open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:UsersRamdasDocumentsEmployee1.mdb;Persist Security Info=False"
r.Opensql, c, adOpenDynamic, adLockPessimistic
Call display
End Sub
Private Sub display()
If Not r.EOFOrr.BOF Then
Text1.Text = r.Fields(0)
Text2.Text = r.Fields(1)
Text3.Text = r.Fields(2)
Text4.Text = r.Fields(3)
End If
End Sub