Private Sub CmdLuu_Click()
Dim Col As Byte
Dim BC As String
Dim BS As String
Dim Sum As String
Worksheets("DATA").Activate 'Con sheet Data de nhap lieu
Col = Cells(2, Columns.Count).End(xlToLeft).Column + 1 'Kiem tra xem cot thu 2 co du lieu chua? chua co chuyen sang cot 3
' kiem tra cac text co du lieu chua
If Trim(Me.cbxKieuHD.Value) = "" Then
Me.cbxKieuHD.SetFocus
MsgBox "Chua nhap Kieu Hop Dong"
Exit Sub
End If
If Trim(Me.cbxNhanvien.Value) = "" Then
Me.cbxNhanvien.SetFocus
MsgBox "Chon nhan vien luu ho so"
Exit Sub
End If
If Trim(Me.txtNgayluu.Value) = "" Then
Me.txtNgayluu.SetFocus
MsgBox "Chua nhap Ngay luu"
Exit Sub
End If
If Trim(Me.txtSocongchung.Value) = "" Then
Me.txtSocongchung.SetFocus
MsgBox "Chua nhap So Hop Dong"
Exit Sub
End If
If Trim(Me.txtDS1.Value) = "" Then
Me.txtDS1.SetFocus
MsgBox "Vui long nhap ten Duong Su 1"
Exit Sub
End If
If Trim(Me.txtDiachi.Value) = "" Then
Me.txtDiachi.SetFocus
MsgBox "Vui long nhap ten Dia chi khach hang"
Exit Sub
End If
'*******Copy du lieu chuyen vao sheet**************
Cells(2, Col).Value = Me!txtDS1.Text:
Cells(4, Col).Value = Me!cbxKieuHD.Text:
Cells(5, Col).Value = TxtToDate(Me!txtNgayluu.Text):
Cells(6, Col).Value = Me!cbxNhanvien.Text:
Cells(7, Col).Value = "Ngày " & Day(TxtToDate(Me!txtNgayluu.Text)) & " " & " tháng " & " " & Month(TxtToDate(Me!txtNgayluu.Text)) & " n" & ChrW(259) & "m " & Year(TxtToDate(Me!txtNgayluu.Text)):
Cells(8, Col).Value = "'" & Me!txtSocongchung.Text:
Cells(9, Col).Value = Me!txtDS1.Text:
Cells(10, Col).Value = Me!txtDiachi.Text:
Cells(11, Col).Value = "'" & Me!txtSodt.Value:
Cells(12, Col).Value = Me!cbxLoaiHD.Text:
Cells(13, Col).Value = Me!txtDS2.Text:
Cells(14, Col).Value = Me!txtDS3.Text:
Cells(15, Col).Value = Me!txtDS4.Text:
Cells(16, Col).Value = Me!txtDS5.Text:
Cells(17, Col).Value = Me!txtDS6.Text:
Cells(18, Col).Value = Me!txtDS7.Text:
Cells(19, Col).Value = Me!txtDS8.Text:
Cells(20, Col).Value = Me!txtDS9.Text:
Cells(21, Col).Value = Me!txtDS10.Text:
Cells(22, Col).Value = Me!txtDS11.Text:
Cells(23, Col).Value = Me!txtBL2.Text:
Cells(24, Col).Value = Me!cbxGT2.Text:
Cells(25, Col).Value = Me!txtBC2.Value:
Cells(26, Col).Value = Me!txtBS2.Value:
Cells(27, Col).Value = Me!txtBL3.Text:
Cells(28, Col).Value = Me!cbxGT3.Text:
Cells(29, Col).Value = Me!txtBC3.Value:
Cells(30, Col).Value = Me!txtBS3.Value:
Cells(31, Col).Value = Me!txtBL4.Text:
Cells(32, Col).Value = Me!cbxGT4.Text:
Cells(33, Col).Value = Me!txtBC4.Value:
Cells(34, Col).Value = Me!txtBS4.Value:
Cells(35, Col).Value = Me!txtBL5.Text:
Cells(36, Col).Value = Me!cbxGT5.Text:
Cells(37, Col).Value = Me!txtBC5.Value:
Cells(38, Col).Value = Me!txtBS5.Value:
Cells(39, Col).Value = Me!txtBL6.Text:
Cells(40, Col).Value = Me!cbxGT6.Text:
Cells(41, Col).Value = Me!txtBC6.Value:
Cells(42, Col).Value = Me!txtBS6.Value:
Cells(43, Col).Value = Me!txtBL7.Text:
Cells(44, Col).Value = Me!cbxGT7.Text:
Cells(45, Col).Value = Me!txtBC7.Value:
Cells(46, Col).Value = Me!txtBS7.Value:
Cells(47, Col).Value = Me!txtBL8.Text:
Cells(48, Col).Value = Me!cbxGT8.Text:
Cells(49, Col).Value = Me!txtBC8.Value:
Cells(50, Col).Value = Me!txtBS8.Value:
Cells(51, Col).Value = Me!txtBL9.Text:
Cells(52, Col).Value = Me!cbxGT9.Text:
Cells(53, Col).Value = Me!txtBC9.Value:
Cells(54, Col).Value = Me!txtBS9.Value:
BC = CDbl(Me!txtBC9) + CDbl(Me!txtBC8) + CDbl(Me!txtBC7) + CDbl(Me!txtBC6) + CDbl(Me!txtBC5) + CDbl(Me!txtBC4) + CDbl(Me!txtBC3) + CDbl(Me!txtBC2) + 1:
BC = CDbl(Me!txtBS9) + CDbl(Me!txtBS8) + CDbl(Me!txtBS7) + CDbl(Me!txtBS6) + CDbl(Me!txtBS5) + CDbl(Me!txtBS4) + CDbl(Me!txtBS3) + CDbl(Me!txtBS2):
Sum = CDbl(BS) + CDbl(BC)
Cells(55, Col).Value = BC:
Cells(56, Col).Value = BS:
Cells(57, Col).Value = Sum:
Cells(58, Col).Value = TxtToDate(Me!txtNgayPH2.Text):
Cells(59, Col).Value = TxtToDate(Me!txtNgayPH3.Text):
Cells(60, Col).Value = TxtToDate(Me!txtNgayPH4.Text):
Cells(61, Col).Value = TxtToDate(Me!txtNgayPH5.Text):
Cells(62, Col).Value = TxtToDate(Me!txtNgayPH6.Text):
Cells(63, Col).Value = TxtToDate(Me!txtNgayPH7.Text):
Cells(64, Col).Value = TxtToDate(Me!txtNgayPH8.Text):
Cells(65, Col).Value = TxtToDate(Me!txtNgayPH9.Text):
'*******Ket thuc nhap lieu****************
MsgBox "Nhâp Xong!", , "Thông báo!"
'xóa du lieu tren form
Me.txtDS1.Value = ""
Me.cbxKieuHD.Value = ""
Me.txtNgayluu.Value = ""
Me.cbxNhanvien.Value = ""
Me.txtSocongchung.Value = ""
Me.txtDS1.Value = ""
Me.txtDiachi.Value = ""
Me.txtSodt.Value = ""
Me.cbxLoaiHD.Value = ""
Me.txtDS2.Value = ""
Me.txtDS3.Value = ""
Me.txtDS4.Value = ""
Me.txtDS5.Value = ""
Me.txtDS6.Value = ""
Me.txtDS7.Value = ""
Me.txtDS8.Value = ""
Me.txtDS9.Value = ""
Me.txtDS10.Value = ""
Me.txtDS11.Value = ""
Me.txtBL2.Value = ""
Me.cbxGT2.Value = ""
Me.txtBC2.Value = ""
Me.txtBS2.Value = ""
Me.txtBL3.Value = ""
Me.cbxGT3.Value = ""
Me.txtBC3.Value = ""
Me.txtBS3.Value = ""
Me.txtBL4.Value = ""
Me.cbxGT4.Value = ""
Me.txtBC4.Value = ""
Me.txtBS4.Value = ""
Me.txtBL5.Value = ""
Me.cbxGT5.Value = ""
Me.txtBC5.Value = ""
Me.txtBS5.Value = ""
Me.txtBL6.Value = ""
Me.cbxGT6.Value = ""
Me.txtBC6.Value = ""
Me.txtBS6.Value = ""
Me.txtBL7.Value = ""
Me.cbxGT7.Value = ""
Me.txtBC7.Value = ""
Me.txtBS7.Value = ""
Me.txtBL8.Value = ""
Me.cbxGT8.Value = ""
Me.txtBC8.Value = ""
Me.txtBS8.Value = ""
Me.txtBL9.Value = ""
Me.cbxGT9.Value = ""
Me.txtBC9.Value = ""
Me.txtBS9.Value = ""
Me.cbxKieuHD.SetFocus
End Sub