Public Function SLgTon(Ma, so As Integer) As Integer
If IsNull(Ma) Or Ma = "" Then
SLgTon = 0
Exit Function
End If
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim StrSQL As String
Set DB = CurrentDb
StrSQL = "SELECT DMHH.MAHANG, IIF(ISNULL(SLTONDAU),0,SLTONDAU)AS TONDAU, " & _
"Sum(IIf(SOPHIEU Like 'N*', SOLUONG, 0)) AS NHAP, " & _
"Sum(IIf(SOPHIEU Like 'X*', SOLUONG, 0)) AS XUAT, " & _
"TONDAU + NHAP - XUAT AS TONCUOI " & _
"FROM DMHH LEFT JOIN CTPNX ON DMHH.MAHANG = CTPNX.MAHANG " & _
"GROUP BY DMHH.MAHANG, IIF(ISNULL(SLTONDAU),0,SLTONDAU) " & _
"HAVING DMHH.MAHANG='" & Ma & "' "
Set RS = DB.OpenRecordset(StrSQL)
SLgTon = IIf(IsNull(RS!TONCUOI), 0, RS!TONCUOI + so) 'Cong lai so cu khi sua so luong xuat
End Function
e xin cam on may anh nheiu