tronghieu9792 > 27-04-17, 08:25 AM
ongke0711 > 27-04-17, 09:33 AM
tronghieu9792 > 27-04-17, 11:57 AM
ongke0711 > 27-04-17, 05:10 PM
Option Compare Database
Option Explicit
Const conJetDate = "\#mm\/dd\/yyyy\#"
Sub AddNewToTable(rstFromTable As DAO.Recordset, rstToTable As DAO.Recordset)
Dim fld As DAO.Field
rstFromTable.MoveFirst
Do While Not rstFromTable.EOF
rstToTable.AddNew
For Each fld In rstFromTable.Fields
rstToTable(fld.Name).Value = rstFromTable(fld.Name).Value
Next fld
rstToTable.Update
rstFromTable.MoveNext
Loop
End Sub
Private Sub cmdNoiDuLieu_Click()
Dim db As DAO.Database
Dim rstA As DAO.Recordset, rstB As DAO.Recordset
Dim strSQL As String, strDateCrit As String
Set db = CurrentDb
Set rstB = db.OpenRecordset("SELECT tableB.Ngay FROM tableB GROUP BY tableB.Ngay", dbOpenDynaset)
With rstB
.MoveFirst
Do Until .EOF
strDateCrit = strDateCrit & Format(!Ngay, conJetDate) & ","
.MoveNext
Loop
End With
strDateCrit = Left(strDateCrit, Len(strDateCrit) - 1)
strSQL = "SELECT queryA.* FROM queryA " & _
"WHERE queryA.Ngay Not In (" & strDateCrit & ")"
Set rstA = db.OpenRecordset(strSQL, dbOpenSnapshot)
Set rstB = db.OpenRecordset("tableB", dbOpenDynaset)
Debug.Print strSQL
Call AddNewToTable(rstA, rstB)
End Sub
tronghieu9792 > 27-04-17, 05:51 PM
tronghieu9792 > 28-04-17, 02:31 PM
tronghieu9792 > 28-04-17, 03:23 PM
ongke0711 > 29-04-17, 12:36 AM
(28-04-17, 02:31 PM)tronghieu9792 Đã viết: Xin hỏi khi áp dụng đoạn code trên thì báo màu vàng ở dòng:
.MoveFirst
Khi thay vào là:
rstB.MoveFirst
thì báo màu vàng dòng:
strDateCrit = strDateCrit & Format(!Ngay, conJetDate) & ","