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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT DISTINCT comboboxes

Status
Not open for further replies.

msay

Programmer
Aug 17, 2001
56
US
I'm using VB6. Trying to fill 3 comboboxes with distinct values from a database. I'm using the following code:
'\\\\\\\\\\\\\
Dim db1 As DAO.Database
Dim rst1 As DAO.Recordset
SQL = "SELECT DISTINCT invoicenum, boat, workdate FROM timesheet"
Set db1 = DBEngine.OpenDatabase("c:\bclub\boatclubData32.mdb")
'Open the Recordset
Set rst1 = db1.OpenRecordset(SQL, dbOpenSnapshot)

rst1.MoveFirst
While Not rst1.EOF
Combo5.AddItem rst1!invoicenum
Combo6.AddItem rst1!boat
Combo7.AddItem rst1!workdate
rst1.MoveNext
Wend
'\\\\\\\\\\\\
My question is; When I eliminate the 3dr item(combo7.addItem) combo5 and combo6 fill with no duplicates. But when I add combo7 and change my SQL by adding "workdate" the boxes fill, but with dupilcates as well. Why?????
Thanks for any help!
 
The distinct keyword works on a records level. That is it checks the combination of all fields and pulls unique records. There can be two fields the same with a third field different. Thus the records are still distinct.

You might need multiple SQL statements to fill your combos.

zemp
 
Thank you. I used mulitple statements.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top