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

how to fill a list box with distinct field values

Status
Not open for further replies.

susu

Technical User
May 15, 2001
5
US
Hello,
I am new to this. I wrote this vba code that once you hit a command button it it queries the selected fields ( geography, year, qtr, industry, sex and age) and puts their distinct values into their corresponding list boxes.
but in the industry field i keep getting this error message
run-time error '2176' 'the setting for this proporty is too long'

a snapshot of the code:
Private function getquery(field as string, table as
string)
dim rtabel as string
set rtable=currentdb.openrecordset("select
distinct "& field & " from [" & table & "] order
by " & field & " asc;")

private sub cmdselecttabletoquery_click()
dim tbl1 as string
if checkgeog(tbl1)="sic3" then
forms!ledform!lstindustry.rowsource=getquery
("sic3",tbl1)
end if
Thanks in advance for any help
 
Hi susu,

Your RowSource should be the SQL statement itself and NOT the result of executing the SQL.

Code:
 forms!ledform!lstindustry.rowsource = "select distinct sic3 from tbl1 order by sic3 asc"

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top