DoCmd.runSQL

alarants

Registered User.
Local time
Today, 09:27
Joined
Apr 17, 2009
Messages
46
Hi,
I am running a code

Public Sub SQL()
Dim Name As String
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
strSQL = "SELECT Koondaurane.Person" & _
"FROM Koondaurane" & _
"GROUP BY Koondaurane.Person;"

Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
Name = rs!Person
Set rs = Nothing
Set db = Nothing
End Sub

It works as long as I have one row in query but geting "missing operator" when there are more rows. What should I do to get all of the rows or to say what row to read?
 
This is becuase you have not got any spaces between the words on the lines
 
Thank you, it works now. I can read now first row of the query. What should I do to read the other rows too?
 
Once you have set the recordset you need the following to step through the results, if any.

Code:
Set Rs = ....

If not Rs.EOF and Not Rs.BOF Then
   Do Until Rs.EOF
      You code here
      Rs.MoveNext
   Loop
   Rs.Close
End If
Set Rs = Nothing

David
 
Shouldn't it go like this:

Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.edit ' NEW LINE
Name = rs!Person
rs.update ' NEW LINE
Set rs = Nothing
Set db = Nothing
 
Rs.Edit
Rs.AddNew
Rs.Delete
Rs.Update

Etc...

Are only needed if you are affecting the recordset. If you are only reading the recordset then there is no need to qualify your actions.

David
 

Users who are viewing this thread

Back
Top Bottom