Dim con As New Connection
Dim r As New Recordset
Dim s As String
Private Sub cmdAddNew_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub cmdDelete_Click()
Dim delid As Integer
Dim ch As Integer
r.Close
delid = Val(InputBox("Enter EID to delete"))
s = "select * from try where empid=" & delid & ""
r.Open s, con, adOpenDynamic, adLockOptimistic
If Not r.EOF And Not r.BOF Then
ch = MsgBox("Do you Really want to delete the record", vbQuestion + vbOKCancel, "Delete Record")
If ch = 1 Then
r.Close
s = "delete from try where empid=" & delid & ""
r.Open s, con, adOpenDynamic, adLockOptimistic
MsgBox "Record Deleted", vbInformation + vbOKOnly, "Deleted"
s = "select * from try"
r.Open s, con, adOpenDynamic, adLockOptimistic
If Not r.EOF And Not r.BOF Then
r.MoveFirst
Call loaddata
Else
MsgBox ("There is no records")
End If
Else
Exit Sub
End If
Else
MsgBox "There is no record found"
Exit Sub
End If
End Sub
Private Sub cmdNext_Click()
r.MoveNext
If Not r.EOF And Not r.BOF Then
Call loaddata
Else
MsgBox ("No More recors to display")
r.MoveFirst
Call loaddata
End If
End Sub
Private Sub cmdPrevious_Click()
r.MovePrevious
If Not r.EOF And Not r.BOF Then
Call loaddata
Else
MsgBox ("No More recors to display")
r.MoveFirst
Call loaddata
End If
End Sub
Private Sub cmdSave_Click()
Dim id As Integer
r.MoveLast
id = r.Fields(0).Value
id = id + 1
r.Close
s = "insert into try values (" & id & " , '" & Text1.Text & "' , ' " & Text2.Text & " ', ' " & Text3.Text & "', '" & Text4.Text & "')"
r.Open s, con, adOpenDynamic, adLockOptimistic
MsgBox "Data Inserted"
s = "select * from try"
r.Open s, con, adOpenDynamic, adLockOptimistic
r.MoveFirst
Call loaddata
End Sub
Private Sub cmdSearch_Click()
Dim srch As Integer
srch = Val(InputBox("Enter EID to search"))
r.Close
s = "select * from try where empid=" & srch & " "
r.Open s, con, adOpenDynamic, adLockOptimistic
If Not r.EOF And Not r.BOF Then
Call loaddata
Else
MsgBox ("Data Not Found")
End If
End Sub
Private Sub cmdUpdate_Click()
Dim id As Integer
Dim ch As Integer
id = r.Fields(0).Value
s = "update try set ename='" & Text1.Text & " ', esalary='" & Text2.Text & " ', emobile= '" & Text3.Text & "', edoj='" & Text4.Text & "' where empid like " & id & " "
ch = MsgBox("Do you Really want to update the record", vbQuestion + vbYesNo, "Delete Record")
If ch = 6 Then
r.Close
r.Open s, con, adOpenDynamic, adLockOptimistic
MsgBox "Data Updated Successfully", vbInformation, "Updated"
s = " Select * from try"
' r.Close
r.Open s, con, adOpenDynamic, adLockOptimistic
r.MoveFirst
Call loaddata
Else
s = " Select * from try"
r.Close
r.Open s, con, adOpenDynamic, adLockOptimistic
r.MoveFirst
Call loaddata
Exit Sub
End If
End Sub
Private Sub Form_Load()
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Ramdas\Documents\dummy.mdb;Persist Security Info=False"
s = "select * from try"
r.Open s, con, adOpenDynamic, adLockOptimistic
If Not r.EOF And Not r.BOF Then
r.MoveFirst
Call loaddata
Else
MsgBox "No records Found", vbOKOnly + vbInformation, "No Records"
End If
End Sub
Private Sub loaddata()
Text1.Text = r.Fields(1).Value
Text2.Text = r.Fields(2).Value
Text3.Text = r.Fields(3).Value
Text4.Text = r.Fields(4).Value
End Sub
Dim r As New Recordset
Dim s As String
Private Sub cmdAddNew_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub cmdDelete_Click()
Dim delid As Integer
Dim ch As Integer
r.Close
delid = Val(InputBox("Enter EID to delete"))
s = "select * from try where empid=" & delid & ""
r.Open s, con, adOpenDynamic, adLockOptimistic
If Not r.EOF And Not r.BOF Then
ch = MsgBox("Do you Really want to delete the record", vbQuestion + vbOKCancel, "Delete Record")
If ch = 1 Then
r.Close
s = "delete from try where empid=" & delid & ""
r.Open s, con, adOpenDynamic, adLockOptimistic
MsgBox "Record Deleted", vbInformation + vbOKOnly, "Deleted"
s = "select * from try"
r.Open s, con, adOpenDynamic, adLockOptimistic
If Not r.EOF And Not r.BOF Then
r.MoveFirst
Call loaddata
Else
MsgBox ("There is no records")
End If
Else
Exit Sub
End If
Else
MsgBox "There is no record found"
Exit Sub
End If
End Sub
Private Sub cmdNext_Click()
r.MoveNext
If Not r.EOF And Not r.BOF Then
Call loaddata
Else
MsgBox ("No More recors to display")
r.MoveFirst
Call loaddata
End If
End Sub
Private Sub cmdPrevious_Click()
r.MovePrevious
If Not r.EOF And Not r.BOF Then
Call loaddata
Else
MsgBox ("No More recors to display")
r.MoveFirst
Call loaddata
End If
End Sub
Private Sub cmdSave_Click()
Dim id As Integer
r.MoveLast
id = r.Fields(0).Value
id = id + 1
r.Close
s = "insert into try values (" & id & " , '" & Text1.Text & "' , ' " & Text2.Text & " ', ' " & Text3.Text & "', '" & Text4.Text & "')"
r.Open s, con, adOpenDynamic, adLockOptimistic
MsgBox "Data Inserted"
s = "select * from try"
r.Open s, con, adOpenDynamic, adLockOptimistic
r.MoveFirst
Call loaddata
End Sub
Private Sub cmdSearch_Click()
Dim srch As Integer
srch = Val(InputBox("Enter EID to search"))
r.Close
s = "select * from try where empid=" & srch & " "
r.Open s, con, adOpenDynamic, adLockOptimistic
If Not r.EOF And Not r.BOF Then
Call loaddata
Else
MsgBox ("Data Not Found")
End If
End Sub
Private Sub cmdUpdate_Click()
Dim id As Integer
Dim ch As Integer
id = r.Fields(0).Value
s = "update try set ename='" & Text1.Text & " ', esalary='" & Text2.Text & " ', emobile= '" & Text3.Text & "', edoj='" & Text4.Text & "' where empid like " & id & " "
ch = MsgBox("Do you Really want to update the record", vbQuestion + vbYesNo, "Delete Record")
If ch = 6 Then
r.Close
r.Open s, con, adOpenDynamic, adLockOptimistic
MsgBox "Data Updated Successfully", vbInformation, "Updated"
s = " Select * from try"
' r.Close
r.Open s, con, adOpenDynamic, adLockOptimistic
r.MoveFirst
Call loaddata
Else
s = " Select * from try"
r.Close
r.Open s, con, adOpenDynamic, adLockOptimistic
r.MoveFirst
Call loaddata
Exit Sub
End If
End Sub
Private Sub Form_Load()
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Ramdas\Documents\dummy.mdb;Persist Security Info=False"
s = "select * from try"
r.Open s, con, adOpenDynamic, adLockOptimistic
If Not r.EOF And Not r.BOF Then
r.MoveFirst
Call loaddata
Else
MsgBox "No records Found", vbOKOnly + vbInformation, "No Records"
End If
End Sub
Private Sub loaddata()
Text1.Text = r.Fields(1).Value
Text2.Text = r.Fields(2).Value
Text3.Text = r.Fields(3).Value
Text4.Text = r.Fields(4).Value
End Sub
No comments:
Post a Comment
Note: only a member of this blog may post a comment.