Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with DISTINCT 1

Status
Not open for further replies.

johnnyv

Programmer
Jul 13, 2001
216
CA
Hello can any one tell me why..
the following statement returns a record count of 0
strsql = "SELECT * From INV_Prof Where [AdvisorKey] = " & lngAdvisorKey

Yet the following statement returns a recordcount of 1
strsql = "SELECT DISTINCT [ClientName] From INV_Prof Where [AdvisorKey] = " & lngAdvisorKey


There are no records in the Table that meet the above conditions so the returned recordcount should be = 0

??

Thanks
 
Access 97
the DB has a total of 12 records in it but none of the records have data in the field [AdvisorKey] that match the value of lngAdvisorKey
 
Mmmm I think you have your comments the wrong way round.

When you do a SELECT DISTINCT it returns a nonupdatable recordset with a recordcount of zero.

Your first statement returns an updatable recordset, and as there are no existing rows the cursor is set to the 'pending' new record and the recordcount is 1.

If you use DISTINCTROW you will get an updatable recordset.

My Access terminology may be a bit off but it should give you the idea.
 
Thanks for the replys

I tried the DISTINCTROW statement within my sql and it kinda works. What I mean is that if there are no reocrds given a clientname with a certain lngAdvisorKey it will tell so. The problem is that if there are multiple records with the same clientname for a unique lngAdvisorKey then it returns all of them as part of the record set. Here is my code, any comments would be appriciated!!

strsql = "SELECT DISTINCTROW [ClientName] From INV_Prof Where [AdvisorKey] = " & lngAdvisorKey
adorecordset.Open strsql, adoconnection, adOpenStatic, adLockReadOnly
If adorecordset.RecordCount > 0 Then
adorecordset.MoveFirst
Do Until adorecordset.EOF
lstClient_Name.AddItem adorecordset!ClientName
adorecordset.MoveNext
Loop
Else
MsgBox "There are no saved Clients for this Advisor"
End If
' closing connection to DB
adorecordset.Close
Set adorecordset = Nothing
adoconnection.Close
 
You make an excellent point petermeachem

I will give it a try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top