daihoangtu > 23-06-14, 09:06 AM
Minh Tiên > 23-06-14, 11:42 AM
Private Sub Command0_Click()
Dim stt As Integer: stt = 0
Dim intSoluong As Integer
Dim strHoten As String
Dim strTenthuoc As String
Dim i As Integer
Dim j As Integer
Dim rst As Recordset
Dim db As Database
Set db = CurrentDb()
Set rst = db.OpenRecordset("CTDS_New")
If rst.RecordCount > 0 Then
db.Execute "Delete * from CTDS_New"
End If
For i = 1 To DMax("[ID]", "qryDS")
strHoten = DLookup("[Hoten]", "qryDS", "[ID]=" & i & "")
For j = 1 To DMax("[stt]", "Danhmucthuoc")
strTenthuoc = DLookup("[Mathuoc]", "Danhmucthuoc", "[stt]=" & j & "")
intSoluong = Nz(DLookup(strTenthuoc, "TH", "[Hoten]='" & strHoten & "'"), 0)
If intSoluong > 0 Then
stt = stt + 1
rst.AddNew
rst!ID = stt
rst!HOTEN = strHoten
rst!TENTHUOC = strTenthuoc
rst!SOLUONG = intSoluong
rst.Update
End If
Next j
Next i
DoCmd.OpenTable "CTDS_New"
rst.Close
Set db = Nothing
End Sub