Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Query


Message #1 by "LaFerriere, Patrick M." <PLaFerriere@T...> on Thu, 6 Sep 2001 12:26:52 -0400
I don't believe you can use the RecordSet Find method (or any other method 
for that matter) to return distinct values. You'll have to get distinct 
values in the SQL statement you use when executing the Open method of the 
Recordset object. A possible workaround would be to use the RecordSet Sort 
method (you'll have to be sure you set the CursorLocation = adUseClient) to 
sort on the column where you are looking for unique values and do something 
like this. In this example, I'm putting the unique values in a combobox 
called Combo1:

...do the stuff to get the recordset "oRs"
oRs.Sort = "ColumnName"
oRs.MoveFirst
Dim sValue As String
sValue = oRs("ColumnName").Value
Combo1.AddItem sValue
oRs.MoveNext
Do Until oRs.EOF
  If sValue <> oRs("ColumnName").Value Then
   sValue = oRs("ColumnName").Value
   Combo1.AddItem sValue
  End If
  oRs.MoveNext
Loop

Regards,
-Toby


>From: "LaFerriere, Patrick M." <PLaFerriere@T...>
>Date: Thu, 6 Sep 2001 12:26:52 -0400
>X-Message-Number: 19
>
>I have an application that get's distinct values for me from a database. I
>want to recreate that functionality against an ADO recordset. I know the
>seek and find methods have a criteria argument but I don't know how to make
>the find method return distinct values.  Does anyone know how?


  Return to Index