Populating a recordset - Can someone please tell me what I'm doing wrong?

S

Sean Mc

Follows is my code:

Dim rst As New ADODB.Recordset
Dim con As New ADODB.Connection
Set con = CurrentProject.Connection

'This should get a list of records having the same file
extension
strSQl = "SELECT TOP 1 tblPrts.Path " & _
"FROM tblPrts " & _
"GROUP BY tblPrts.Path " & _
"HAVING (tblPrts.Path Like '*" & strExt & "');"
rst.Open strSQl, con, adOpenForwardOnly, adLockReadOnly, -1
If Not rst.EOF Then vntRecs = rst.GetRows

If I paste the SQL str produced by this code into a query it returns a
record, yet this code returns no records.

I've been staring at this and can't figure my problem out. Is my brain still
asleep here and Im missing something obvious?

Thanks,
Sean Mc
 
R

Rick Brandt

Sean Mc said:
Follows is my code:

Dim rst As New ADODB.Recordset
Dim con As New ADODB.Connection
Set con = CurrentProject.Connection

'This should get a list of records having the same file extension
strSQl = "SELECT TOP 1 tblPrts.Path " & _
"FROM tblPrts " & _
"GROUP BY tblPrts.Path " & _
"HAVING (tblPrts.Path Like '*" & strExt & "');"
rst.Open strSQl, con, adOpenForwardOnly, adLockReadOnly, -1
If Not rst.EOF Then vntRecs = rst.GetRows

If I paste the SQL str produced by this code into a query it returns a record,
yet this code returns no records.

I've been staring at this and can't figure my problem out. Is my brain still
asleep here and Im missing something obvious?

The wild card in ADO is % instead of *.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top