Hi, I want to retrieve data that is returned by sql query that I defined in access queries in visual basic. In order to count the rows I know we use DCount() method. What method do I use to get the actual data in the queries? Please Help me on this. Thank you.
This is what I wrote.
And in my querysection, I have query called "testDate1MonthNotice" And within this query, there is 3 field retrieving. SchoolName, P-ID, and TestDate.
I get erroe in here saying that "Item not found in this collection"
With rst.Fields(SchoolName).Value
==============================================
Dim db As DAO.Database, rst As DAO.Recordset
Dim i As Integer
Dim variable As String
Dim msg As String
Set db = CurrentDb
Set rst = db.OpenRecordset("testDate1MonthNotice"
With rst.Fields(SchoolName).Value
If rst.RecordCount <> 0 Then
rst.MoveLast
rst.MoveFirst
For i = 0 To rst.RecordCount
variable = rst!SchoolName
rst.MoveNext
Next i
End If
If variable <> "" Then
MsgBox "hi", vbOKOnly, "Message Title"
End If
End With
I now have changed my code this this
but I get type mismatch error at
Set rst = db.OpenRecordset(SQL)
Any idea?
==========================================
Private Sub Form_Load()
Dim db As Database
Dim rst As Recordset
Dim i As Integer
Dim SQL As String
SQL = "SELECT [school].[schoolName], [Participation].[ParticipationID], [Participation].[TestDAte]" & _
"FROM school RIGHT JOIN Participation ON [Participation].[SchoolID]=[School].[SchooliD]" & _
"WHERE ([Participation].[testDate]-date()<=30 And [Participation].[testDate]-date()>0)"
Set db = CurrentDb
Set rst = db.OpenRecordset(SQL)
If rst.RecordCount <> 0 Then
rst.MoveLast
rst.MoveFirst
For i = 0 To rst.RecordCount
variable = rst.Fields(i)
rst.MoveNext
Next i
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.