duynamvnn1208 > 30-06-17, 06:24 PM
ongke0711 > 30-06-17, 06:31 PM
lehongduc > 30-06-17, 07:43 PM
Function GetrstTemp(qdfTemp As QueryDef)
Dim rstTemp As Recordset
With qdfTemp
Debug.Print .Name
Debug.Print " " & .SQL
Set rstTemp = .OpenRecordset(dbOpenSnapshot)
With rstTemp
.MoveLast
Debug.Print " Number of records = " & .RecordCount
Debug.Print
.Close
End With
End With
End Function
Sub QueryDefX()
Dim dbsNorthwind As Database
Dim qdfNew As QueryDef
Dim qdfLoop As QueryDef
Dim prpLoop As Property
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set qdfNew = dbsNorthwind.CreateQueryDef("NewQueryDef", "SELECT * FROM Categories")
With dbsNorthwind
Debug.Print .QueryDefs.Count & " QueryDefs in " & .Name
For Each qdfLoop In .QueryDefs
Debug.Print " " & qdfLoop.Name
Next qdfLoop
With qdfNew
Debug.Print "Properties of " & .Name
For Each prpLoop In .Properties
On Error Resume Next
Debug.Print " " & prpLoop.Name & " - " & IIf(prpLoop = "", "[empty]", prpLoop)
On Error Goto 0
Next prpLoop
End With
.QueryDefs.Delete qdfNew.Name
.Close
End With
End Sub
lehongduc > 30-06-17, 08:37 PM
Function GetrstTemp(qdfTemp As QueryDef)
Dim rstTemp As Recordset
Dim fld As Field, fldname As String
Dim k As Integer
Dim RecSt As String
With qdfTemp
Debug.Print .Name
Debug.Print " " & .SQL
Set rstTemp = .OpenRecordset(dbOpenSnapshot)
Do Until rstTemp.EOF
k = k + 1
RecSt = ""
For Each fld In rstTemp.Fields
fldname = fld.Name
RecSt = RecSt & " - " & fldname & " : " & rstTemp(fldname)
Next
Debug.Print "- Record " & k
Debug.Print RecSt
rstTemp.MoveNext
Loop
End With
rstTemp.Close
Set rstTemp = Nothing
End Function
Sub CreateQueryDefX()
Dim dbs As Database
Dim qdfTemp As QueryDef
Dim qdfNew As QueryDef
Dim sqlSt As String
Set dbs = CurrentDb()
With dbs
sqlSt = "SELECT Categories.CategoryName, Count(Products.ProductName) AS CountOfProductName"
sqlSt = sqlSt & " FROM Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID"
sqlSt = sqlSt & " GROUP BY Categories.CategoryName;"
Set qdfTemp = .CreateQueryDef("", sqlSt)
GetrstTemp qdfTemp
.Close
End With
Set dbs = Nothing
End Sub
duynamvnn1208 > 01-07-17, 10:23 AM
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Set qdf = CurrentDb.QueryDefs!queryName1
Set rst = qdf.OpenRecordset(dbOpenDynaset, dbForwardOnly)
Do While Not rst.EOF
MsgBox("Thanks All Friends!")
rst.MoveNext
Loop
lehongduc > 01-07-17, 09:16 PM
(01-07-17, 10:23 AM)duynamvnn1208 Đã viết: Ko biết Group By có ảnh hưởng ko các bạnChào Bạn,
duynamvnn1208 > 02-07-17, 09:34 AM
(01-07-17, 09:16 PM)lehongduc Đã viết:(01-07-17, 10:23 AM)duynamvnn1208 Đã viết: Ko biết Group By có ảnh hưởng ko các bạnChào Bạn,
Hình như Bạn không đọc nội dung tôi trả lời.
Trong ví dụ minh họa, tôi đã tạo ra 1 Query với câu lệnh SQL có dùng GROUP BY đó.
Và nếu Bạn test sẽ thấy vẫn OpenRecordset bình thường. Tôi có kèm theo file mdb có ví dụ minh họa vừa nói ở trên, để Bạn khỏi phải nhập lại code mất công.