Hide Duplicated Data in ComboBox

M

March

Hello All,

I would like to write VBA code to hide any duplicated data. I start the code
with query the data from table.

For example:

sqlcmd = "<query>"

set xAccountRST = db.openrecordset(sqlcmd)

xAccountRST.movelast

n = xAccountRST.recordcount

xAccountRST.movefirst

For i = 1 to n

Combo1.HideDuplicates = True

Combo1.RowSourceType = "Value List"

Combo1.AddItem Item:=xAccount

xAccountRST.MoveNext

Next n

From code above, in the query I use "Distinct". The result of add item
listed the combo box has the duplicated data.

Please give me suggestion.

Thank you ,

March
 
D

Douglas J. Steele

Is there some reason you're not setting the RowSourceType to "Table/Query"
and setting the RowSource to the query?
 
M

March

I try to use "Table/Query" but when run the application, it requires to enter
parameter value. That is not work in the way I want my application to be.

I don't know this would help you to answer my question or not?
 
D

Douglas J. Steele

That implies there's something wrong with your query.

What's the SQL you're trying to use?
 
M

March

The query:


sqlcmd = "SELECT distinct <field1> from tb1;"



that's simple. With the query doesn't show any duplicated by using distinct.


Let say, I have combo1 in the beginning.

After combo1 lost focus, the process will take place to the query. Next will
add item in combo2.


If I'm not clear in some point, please ask me.

Thanks,

March
 
D

Douglas J. Steele

It may be simple, but it's obviously not your actual SQL. While you may
think you're helping things by generalizing in your question, often it's the
specifics of what you're using that cause the problem. For instance, if the
field name has spaces in it and you don't use square brackets around the
name, you'll have a problem.

Is what you're trying to say is that once focus moves from Combo1, suddenly
it has duplicate entries in it that weren't there before? Try setting the
RowSource property to an empty string before adding the new rows.
 

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

Similar Threads


Top