quanghoasla > 20-05-11, 02:22 PM
quanghoasla > 20-05-11, 03:00 PM
haquocquan > 20-05-11, 04:16 PM
Dim rsHS as Recordset
Dim rsMH as Recordset
Dim rsDIEM as Recordset
Set rsHS = CurrentDb.OpenRecordset("hocvien")
Set rsMH = CurrentDb.OpenRecordset("monhoc")
Set rsDIEM = CurrentDb.OpenRecordset("diem", dbOpenDynaset)
rsHS.MoveFirst
Do Until rsHS.EOF
rsMH.MoveFirst
Do Until rsMH.EOF
rsDIEM.AddNew
rsDIEM!idsv = rsHS!idsv
rsDIEM!monhoc = rsMH!monhoc
rsDIEM.Update
rsMH.MoveNext
Loop
rsHS.MoveNext
Loop
rsHS.Close
rsMH.Close
rsDIEM.Close
Noname > 20-05-11, 04:30 PM
sql1 = "INSERT INTO diem ( idsv, tenmon ) SELECT hocvien.idsv, monhoc.tenmon FROM hocvien, monhoc"
DoCmd.RunSQL sql1
quanghoasla > 20-05-11, 05:14 PM
quanghoasla > 24-05-11, 11:39 AM
haquocquan > 24-05-11, 10:59 PM
Dim SQLHS as String
Dim rsHS as Recordset
Dim rsMH as Recordset
Dim rsDIEM as Recordset
SQLHS = "SELECT hocvien.idsv from hocvien WHERE (((hocvien.idsv) Not In (SELECT diem.idsv FROM diem GROUP BY diem.idsv)))"
Set rsHS = CurrentDb.OpenRecordset(SQLHS)
Set rsMH = CurrentDb.OpenRecordset("monhoc")
Set rsDIEM = CurrentDb.OpenRecordset("diem", dbOpenDynaset)
if rshs.RecordCount>0 then
rsHS.MoveFirst
Do Until rsHS.EOF
rsMH.MoveFirst
Do Until rsMH.EOF
rsDIEM.AddNew
rsDIEM!idsv = rsHS!idsv
rsDIEM!monhoc = rsMH!monhoc
rsDIEM.Update
rsMH.MoveNext
Loop
rsHS.MoveNext
Loop
End if
rsHS.Close
rsMH.Close
rsDIEM.Close
quanghoasla > 27-05-11, 12:33 PM
(24-05-11, 10:59 PM)haquocquan Đã viết: Bạn thử đoạn code này xem sao nhé:-------------------------------------------------------------------------------------------------------------------------
Mã:Dim SQLHS as String
Dim rsHS as Recordset
Dim rsMH as Recordset
Dim rsDIEM as Recordset
SQLHS = "SELECT hocvien.idsv from hocvien WHERE (((hocvien.idsv) Not In (SELECT diem.idsv FROM diem GROUP BY diem.idsv)))"
Set rsHS = CurrentDb.OpenRecordset(SQLHS)
Set rsMH = CurrentDb.OpenRecordset("monhoc")
Set rsDIEM = CurrentDb.OpenRecordset("diem", dbOpenDynaset)
if rshs.RecordCount>0 then
rsHS.MoveFirst
Do Until rsHS.EOF
rsMH.MoveFirst
Do Until rsMH.EOF
rsDIEM.AddNew
rsDIEM!idsv = rsHS!idsv
rsDIEM!monhoc = rsMH!monhoc
rsDIEM.Update
rsMH.MoveNext
Loop
rsHS.MoveNext
Loop
End if
rsHS.Close
rsMH.Close
rsDIEM.Close
Bạn nên post file lên để mọi người hỗ trợ trực tiếp. Còn nếu không có file, chỉ là thuật toán thôi, không chạy thử được nên không biết có ổn không.
quanghoasla > 27-05-11, 05:52 PM