Thứ Ba

Thêm xóa Sửa Trong access vba

Private Sub cmdthem_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("HoaDon")
Dim dem As Integer
dem = 0
Do While rs.EOF = False
If rs!MaHD = txtmahd.Value Then
dem = 1
Exit Do
End If
rs.MoveNext
Loop
If dem = 1 Then
MsgBox "Ma nay da ton tai", vbOKOnly, "Thong bao!"
Exit Sub
Else
rs.AddNew
rs!MaHD = txtmahd.Value
rs!NgayLHD = txtnlhd.Value
rs!MaKH = txtmakh.Value
rs!MaNV = txtmanv.Value
On Error Resume Next
rs.Update
MsgBox "Ban da luu du lieu thanh cong"
txtmahd.Value = Delete
txtnlhd.Value = Delete
txtmakh.Value = Delete
txtmanv.Value = Delete
End If
End Sub

Private Sub cmdsua_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("HoaDon")
Do While rs.EOF = False
If rs!MaHD = txtmahd.Value Then
rs.Edit
rs!MaHD = txtmahd.Value
rs!NgayLHD = txtnlhd.Value
rs!MaKH = txtmakh.Value
rs!MaNV = txtmanv.Value
rs.Update
MsgBox "Ban da suu du lieu thanh cong", vbOKOnly, "Thong bao!"
txtmahd.Value = Delete
txtnlhd.Value = Delete
txtmakh.Value = Delete
txtmanv.Value = Delete
Exit Do
End If
rs.MoveNext
Loop
rs.Close
End Sub

Private Sub cmdtim_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("HoaDon")
Do While rs.EOF = False
If rs!MaHD = txttim.Value Then
MsgBox "Ma hoa don " & " " & txttim & " " & "da duoc tim thay"
txtmahd.Value = rs.Fields("MaHD").Value
txtnlhd.Value = rs.Fields("NgayLHD").Value
txtmakh.Value = rs.Fields("MaKH").Value
txtmanv.Value = rs.Fields("MaNV").Value
Exit Do
End If
rs.MoveNext
Loop
End Sub

Private Sub cmdxoa_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("HoaDon")
Do While rs.EOF = False
If rs!MaHD = txtmahd.Value Then
If MsgBox("Ban muon xoa du lieu", vbOKCancel, "Thong bao!") = vbOK Then
rs.Delete
MsgBox "Ban da xoa du lieu thanh cong", vbOKOnly, "Thong bao!"
txtmahd.Value = Delete
End If
Exit Do
End If
rs.MoveNext
Loop
End Sub

1 nhận xét:

Unknown nói...

cho e xin code nút lui tới trước sau với

Đăng nhận xét

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Blogger Templates