025777 > 05-03-12, 12:39 AM
Trích dẫn:Private Sub cmdXemKQ_Click()
Dim chk As Integer
Dim db As Database
Dim qdf As QueryDef
Dim strSQL As String
Dim strDateFrom As String
Dim strDateTo As String
Dim RevMonth As Double
Dim RevPeriod As Double
Dim ProfitMonth As Double
Dim CostMonth As Double
Dim CostPeriod As Double
Dim ProfitPeriod As Double
Dim dte As Date
Set db = CurrentDb
'Kiem tra loai bao cao
If cboChonBaoCao.Value = "Báo cáo KQKD" Then chk = 1
If cboChon.Value = "Báo cáo l??ng" Then chk = 2
If cboChon.Value = "Báo cáo b?o hi?m" Then chk = 3
If cboChon.Value = "Báo cáo thu? TNCN" Then chk = 4
Select Case chk
Case 1
Set qdf = db.QueryDefs("qryXemKQKD")
'Xem 1 NV theo thang
If cboChon = "Cá nhân" Then
If optGiaiDoan.Value = False Then
If IsNull(cboThang) Or IsNull(cboNam) Or IsNull(txtMaNV) Then
MsgBox "Ban chua chon du thong tin "
Exit Sub
Else
Select Case cboThang
Case "1", "3", "5", "7", "8", "10", "12"
strSQL = "SELECT tblHopDong.MaNV, tblNhanVien.HoTen, tblHopDong.Ngay, tblHopDong.CongTY, tblHopDong.HopDongID, tblHopDong.DoanhThu, tblHopDong.ChiPhi, tblHopDong.LoiNhuan, tblHopDong.ThanhToan, DSum('DoanhThu','tblHopDong','[MaNV] = Forms![frmXemKQKD]![cboMaNV] and [Ngay]>= CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam]) And [Ngay] <=CDate([Forms]![frmXemKQKD]![cboThang] & '/31/' & [Forms]![frmXemKQKD]![cboNam])') AS TongDT, DSum('ChiPhi','tblHopDong','[MaNV] = Forms![frmXemKQKD]![cboMaNV] and [Ngay]>= CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam]) And [Ngay] <=CDate([Forms]![frmXemKQKD]![cboThang] & '/31/' & [Forms]![frmXemKQKD]![cboNam])') AS TongCP, [TongDT]-[TongCP] AS TongLN FROM tblNhanVien INNER JOIN tblHopDong ON tblNhanVien.MaNV = tblHopDong.MaNV WHERE (((tblHopDong.MaNV)=[Forms]![frmXemKQKD]![cboMaNV])" & _
"AND ((tblHopDong.Ngay)>=CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam])) AND ((tblHopDong.Ngay)<=CDate([Forms]![frmXemKQKD]![cboThang] & '/31/' & [Forms]![frmXemKQKD]![cboNam])));"
qdf.SQL = strSQL
DoCmd.OpenReport "rptXemKQKDThang", acViewPreview
Case "2"
strSQL = "SELECT tblHopDong.MaNV, tblNhanVien.HoTen, tblHopDong.Ngay, tblHopDong.HopDongID, tblHopDong.DoanhThu, tblHopDong.ChiPhi, tblHopDong.LoiNhuan, tblHopDong.ThanhToan, DSum('DoanhThu','tblHopDong','[MaNV] = Forms![frmXemKQKD]![cboMaNV] and [Ngay]>= CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam]) And [Ngay] <=CDate([Forms]![frmXemKQKD]![cboThang] & '/28/' & [Forms]![frmXemKQKD]![cboNam])') AS TongDT, DSum('ChiPhi','tblHopDong','[MaNV] = Forms![frmXemKQKD]![cboMaNV] and [Ngay]>= CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam]) And [Ngay] <=CDate([Forms]![frmXemKQKD]![cboThang] & '/28/' & [Forms]![frmXemKQKD]![cboNam])') AS TongCP, [TongDT]-[TongCP] AS TongLN, tblHopDong.CongTy FROM tblNhanVien INNER JOIN tblHopDong ON tblNhanVien.MaNV = tblHopDong.MaNV WHERE (((tblHopDong.MaNV)=[Forms]![frmXemKQKD]![cboMaNV])" & _
"AND ((tblHopDong.Ngay)>=CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam]) And (tblHopDong.Ngay)<=CDate([Forms]![frmXemKQKD]![cboThang] & '/28/' & [Forms]![frmXemKQKD]![cboNam])));"
qdf.SQL = strSQL
DoCmd.OpenReport "rptXemKQKDThang", acViewPreview
Case "4", "6", "9", "11"
strSQL = "SELECT tblHopDong.MaNV, tblNhanVien.HoTen, tblHopDong.Ngay, tblHopDong.CongTY, tblHopDong.HopDongID, tblHopDong.DoanhThu, tblHopDong.ChiPhi, tblHopDong.LoiNhuan, tblHopDong.ThanhToan, DSum('DoanhThu','tblHopDong','[MaNV] = Forms![frmXemKQKD]![cboMaNV] and [Ngay]>= CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam]) And [Ngay] <=CDate([Forms]![frmXemKQKD]![cboThang] & '/30/' & [Forms]![frmXemKQKD]![cboNam])') AS TongDT, DSum('ChiPhi','tblHopDong','[MaNV] = Forms![frmXemKQKD]![cboMaNV] and [Ngay]>= CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam]) And [Ngay] <=CDate([Forms]![frmXemKQKD]![cboThang] & '/30/' & [Forms]![frmXemKQKD]![cboNam])') AS TongCP, [TongDT]-[TongCP] AS TongLN FROM tblNhanVien INNER JOIN tblHopDong ON tblNhanVien.MaNV = tblHopDong.MaNV WHERE (((tblHopDong.MaNV)=[Forms]![frmXemKQKD]![cboMaNV])" & _
"AND ((tblHopDong.Ngay)>=CDate([Forms]![frmXemKQKD]![cboThang] & '/01/' & [Forms]![frmXemKQKD]![cboNam])) AND ((tblHopDong.Ngay)<=CDate([Forms]![frmXemKQKD]![cboThang] & '/30/' & [Forms]![frmXemKQKD]![cboNam])));"
qdf.SQL = strSQL
DoCmd.OpenReport "rptXemKQKDThang", acViewPreview
End Select
End If
End If
End If
End Select
End Sub
Noname > 05-03-12, 01:03 AM
CDate('Jun' & ' 01/' & [Forms]![frmXemKQKD]![cboNam])
Ví dụ: DateSerial('2012','06','01') sẽ trả về ngày 01 tháng 06 năm 2012