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

Populating a drop down menu

Status
Not open for further replies.

ronis

Programmer
Jul 14, 2000
9
0
0
US
I am connecting a web page to an Access database.&nbsp;&nbsp;I would like to populate the combo box with the records from Access.&nbsp;&nbsp;I have no idea how to do this in a web page&nbsp;&nbsp;(This is my first web document).&nbsp;&nbsp;Any suggestions would be greatly appreciated.&nbsp;&nbsp;<br><br>I have checked out many comments about this, but I am unable to get them to work at all.&nbsp;&nbsp;I do have experience in vbscript, but with Outlook forms.<br><br>Thank you for your time.<br><br>
 
You do it like this:<br><br>&lt;select name=&quot;somename&quot;&gt;<br><br>&lt;%<br>&nbsp;&nbsp;RecSet.movefirst&nbsp;&nbsp;<br>&nbsp;&nbsp;do until RecSet.eof<br>%&gt;<br><br>&lt;option value=&quot;&lt;%=RecSet(&quot;somefield&quot;)%&gt;&quot;&gt;&lt;%=RecSet(&quot;somefield&quot;)%&gt;<br><br>&lt;%<br>&nbsp;&nbsp;RecSet.movenext<br>&nbsp;&nbsp;loop<br>%&gt;<br><br>&lt;/select&gt;
 
The thing missing in the above advise opening the table and placing the pointer at the first record.&nbsp;&nbsp;This example lists the first and last name, but sets up to retain the IdNo.&nbsp;&nbsp;Remember to close your recordset and set the variable to null.<br><br>dim rs<br>&nbsp;&nbsp;set rs=server.createobject(&quot;ADODB.recordset&quot;)<br>&nbsp;&nbsp;rs.Open &quot;tablename&quot;, &quot;DSN=DatabaseName&quot;<br>&nbsp;&nbsp;rs.movefirst<br><br>&nbsp;&nbsp;&lt;p&gt;&lt;select name=&quot;lstIdno&quot; size=&quot;1&quot;&gt;<br>&lt;%<br>&nbsp;&nbsp;Do while not rs.EOF<br>&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;&lt;option value='&quot; & rs(&quot;IdNo&quot;) & &quot;'&gt;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;response.write rs(&quot;LName&quot;) & &quot;, &quot; & rs(&quot;FName&quot;)&&quot; &quot; & rs(&quot;Middle&quot;)& &quot;&lt;/option&gt;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;rs.movenext<br>&nbsp;&nbsp;loop<br>&nbsp;&nbsp;rs.close<br>&nbsp;&nbsp;set rs=nothing<br>%&gt;<br><br>&nbsp;&nbsp;&lt;/select&gt; &lt;/p&gt;<br><br>
 
I think that nothing was missing, because I thought that opening recordset is pretty obvious...<br>As for usage of response.write for HTML output, I think it's much more readable and less error-prone to use plain HTML...
 
Thank you both very much for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top