CHƯƠNG 3 THIẾT KẾ HỆ THỐNG
III. Thiết kế các chức năng chương trình
3.5 Form giao diện “Danh mục hàng hóa”
Hình 20: Giao diện danh mục hàng Code Form danh sách hàng hóa
Code các nút lệnh ĐẦU, TRƯỚC, SAU, CUỐI ,THOÁT giống như code Form HÓA ĐƠN
Private Sub IN_WORD_Click() On Error GoTo Err_IN_WORD_Click Dim oApp As Object
Set oApp = CreateObject("Word.Application") oApp.Visible = True
Exit_IN_WORD_Click:
Exit Sub
Err_IN_WORD_Click:
MsgBox Err.Description
Resume Exit_IN_WORD_Click End Sub
Private Sub ghi_Click() On Error GoTo Err_ghi_Click If IsNull(mahh) Then
MsgBox "Khong luu duoc gia tri rong!", vbExclamation + vbDefaultButton1, "chu y"
Exit Sub
Else DoCmd.RunCommand (acCmdSaveRecord) ketqua.Requery
End If
ketqua.Visible = True Me.timkiem.Visible = True dau.Visible = True
truoc.Visible = True sau.Visible = True cuoi.Visible = True them.Visible = True thoat.Visible = True
DoCmd.GoToControl "them"
ghi.Visible = False khong.Visible = False sua.Visible = True xoa.Visible = True Xthem = False Xsua = False
mahh.Locked = True tenhh.Locked = True dvt.Locked = True sltonDK.Locked = True tgtonDK.Locked = True ketqua.Requery
Exit_ghi_Click:
ketqua.Visible = True Me.timkiem.Visible = True dau.Visible = True
sau.Visible = True truoc.Visible = True cuoi.Visible = True thoat.Visible = True ghi.Visible = False khong.Visible = False
xoa.Visible = True sua.Visible = True them.Visible = True
DoCmd.GoToControl "them"
Xthem = False Xsua = False
mahh.Locked = True tenhh.Locked = True dvt.Locked = True sltonDK.Locked = True tgtonDK.Locked = True ketqua.Requery
Exit Sub Err_ghi_Click:
MsgBox "Du lieu nhap khong hop le"
End Sub
Private Sub hien_Click() Me.txtmahh = Null Me.txtten = Null
Me.ketqua.RowSource = "select * from HANGHOA"
End Sub
Private Sub in_Click() End Sub
Private Sub ketqua_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "mahh = '" & Me!ketqua & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark End Sub
Private Sub khong_Click() On Error Resume Next
DoCmd.RunCommand acCmdUndo DoCmd.GoToRecord , , acFirst ketqua.Visible = True
Me.timkiem.Visible = True dau.Visible = True
sau.Visible = True truoc.Visible = True
cuoi.Visible = True thoat.Visible = True sua.Visible = True xoa.Visible = True them.Visible = True them.SetFocus
khong.Visible = False ghi.Visible = False Xthem = False Xsua = False
mahh.Locked = True tenhh.Locked = True dvt.Locked = True sltonDK.Locked = True tgtonDK.Locked = True ketqua.Requery
End Sub
Private Sub sua_Click() On Error GoTo Err_sua_Click mahh.Locked = False tenhh.Locked = False dvt.Locked = False sltonDK.Locked = False tgtonDK.Locked = False mahh.SetFocus
ketqua.Visible = False Me.timkiem.Visible = False dau.Visible = False
sau.Visible = False truoc.Visible = False cuoi.Visible = False sua.Visible = False khong.Visible = True ghi.Visible = True xoa.Visible = False thoat.Visible = False them.Visible = False Xsua = True
Exit_sua_Click:
Exit Sub Err_sua_Click:
MsgBox Err.Description Resume Exit_sua_Click End Sub
Private Sub them_Click()
On Error GoTo Err_them_Click DoCmd.GoToRecord , , acNewRec mahh.Locked = False
tenhh.Locked = False dvt.Locked = False sltonDK.Locked = False tgtonDK.Locked = False mahh.SetFocus
ketqua.Visible = False Me.timkiem.Visible = False dau.Visible = False
sau.Visible = False truoc.Visible = False cuoi.Visible = False sua.Visible = False khong.Visible = True ghi.Visible = True xoa.Visible = False thoat.Visible = False them.Visible = False Xthem = True
Exit_them_Click:
Exit Sub Err_them_Click:
MsgBox Err.Description Resume Exit_them_Click End Sub
Private Sub tim_Click()
If IsNull(txtmahh) = False And IsNull(txtten) = True Then
Me.ketqua.RowSource = "select * from HANGHOA where([HANGHOA]!
[mahh] like '*" & [txtmahh] & "*')"
ElseIf IsNull(txtmahh) = True And IsNull(txtten) = False Then
Me.ketqua.RowSource = "select * from HANGHOA where([HANGHOA]!
tenhh like '*" & [txtten] & "*')"
ElseIf IsNull(txtmahh) = False And IsNull(txtten) = False Then
Me.ketqua.RowSource = "select * from HANGHOA where([HANGHOA]!
[mahh] like '*" & [txtmahh] & "*' or [HANGHOA]![tenhh] like '*" &
[txtten] & "*')"
ElseIf IsNull(txtmahh) = True And IsNull(txtten) = True Then
MsgBox "Ban chua nhap dieu kien tim kiem", 0 + 60, "Thong bao"
End If End If End If End If End Sub
Private Sub xoa_Click() Dim traloi
If IsNull(mahh) Then
MsgBox "Khong the xoa du lieu rong", 48, "chu y"
Else traloi = MsgBox("Ban muon xoa ma hang: " & [mahh] & " (cung nhung mau tin lien quan )?", 48 + 4, "thong bao")
If traloi = 6 Then
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 DoCmd.GoToRecord , , acFirst
ketqua.Requery
DoCmd.SetWarnings True End If
End If
Exit_xoa_Click:
Exit Sub Err_xoa_Click:
MsgBox "khong the xoa mau tin nay"
Resume Exit_xoa_Click End Sub