Forums

ASP

This topic is locked

No duplicates in drop down

Posted 03 Oct 2003 13:44:51
1
has voted
03 Oct 2003 13:44:51 neoz 123 posted:
How do I make it so no duplicate show in a dynamic drop down. Pulling from ACCESS.
<pre id=code><font face=courier size=2 id=code>
Form code :
&lt;form name="frmSelect" method="get" action="dbsearch.asp"&gt;
&lt;!-- Using javascript with ASP for an automatic submit of selected form value***jmeyers --&gt;
&lt;SELECT name=DbName LANGUAGE=javascript onchange="return dept_onchange(frmSelect)" title="Select exercise to display cooresponding observations." style="color: #003366; font-style: normal; font-family: verdana; font-weight: normal; font-size:10px"&gt;
&lt;%
' Populating drop down menu from DbName field in Tbl_Observation table***jmeyers
do until drs.EOF
response.write("&lt;option"
if drs.fields("DbName"=DbName then
response.write("selected"
end if
response.write("&gt;"
response.write(drs.fields("DbName")
drs.MoveNext
loop
drs.Close
set drs=Nothing
%&gt;
&lt;/SELECT&gt;&nbsp;&lt;font size="1"&gt;&lt;font face="Arial, Helvetica, sans-serif" title="Select exercise to display cooresponding observations."&gt;Select exercise&lt;/font&gt;&lt;/font&gt;
&lt;/form&gt;

searchdb page:
&lt;%

If oField &lt;&gt; "" Then


Set conn = Server.CreateObject("ADODB.Connection"
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("AssDB/EFCATDB.mdb")

set rs = Server.CreateObject("ADODB.Recordset"


sql ="SELECT DISTINCT ROW * " _
& "FROM Tbl_Observation WHERE [Tbl_Observation].[DbName] = '" & oField & "'"




Set rs = conn.Execute(sql)


%&gt;
</font id=code></pre id=code>

Replies

Replied 03 Oct 2003 20:09:58
03 Oct 2003 20:09:58 Jon Ford replied:
think this may help...

Try usng a DISTINCT clause in the SQL statement used to create the recordset(s) that are used to populate the drop down boxes. Something like:

SELECT DISTINCT SomeFieldName FROM SomeTableName

Regards

Owen.

Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo


please let me know thanks - Jon
Replied 03 Oct 2003 20:13:17
03 Oct 2003 20:13:17 neoz 123 replied:
Problem already solved


SELECT DISTINCT DbName FROM Tbl_Observation GROUP BY DbName ORDER BY DbName

The Group By eliiminates the duplicates

Reply to this topic