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

Get data to show up in a drop down menu

Status
Not open for further replies.

d1004

Programmer
May 9, 2002
78
US
If I want to get the data from the date field in the database to show up in my html drop down menu, then how can I do that dynamically?
 
[tt]
Create a record set from your database table and follow the code below

<select name=&quot;supervisoremail&quot;>
<option value=&quot;LeftBlank&quot;>Supervisor's Email</option>
<%
While (NOT rsDepartments.EOF)
%>
<option value=&quot;<%=(rsDepartments.Fields.Item(&quot;email&quot;).Value)%>&quot; ><%=(rsDepartments.Fields.Item(&quot;email&quot;).Value)%></option>
<%
rsDepartments.MoveNext()
Wend
If (rsDepartments.CursorType > 0) Then
rsDepartments.MoveFirst
Else
rsDepartments.Requery
End If
%>
</select>

Here I'm selecting all emails supervisors from my department table. Hope it helps...
[tt]&quot;A Successful man is one who can build
a firm foundation with the bricks
that others throw at him&quot;
[/tt]

star.gif
star.gif
star.gif
star.gif

 
You can do something like this:

Dim SQL, rs
SQL = &quot;SELECT DateID, Dates FROM tblDates&quot;
Set rs = connection.execute(SQL)

<select name=&quot;cboList&quot;>
<option value=&quot;&quot;>Select an option</option>
<%
If Not (rs.EOF and rs.BOF) Then
rs.movefirst
Do Until rs.EOF
If CInt(intID) = CInt(rs.fields(&quot;DateID&quot;)) Then%>
<option value=&quot;<%=rs.fields(&quot;DateID&quot;)%>&quot; selected><%=rs.fields(&quot;Dates&quot;)%></option>
<%Else%>
<option value=&quot;<%=rs.fields(&quot;DateID&quot;)%>&quot;><%=rs.fields(&quot;Dates&quot;)%></option>
<%End If
rs.MoveNext
Loop
End If
rs.Close
Set rs = Nothing
%>
</select>
 
This is what I put inside my HTML page, but somehow it doesn't seem to work. Please help!!!

<%
Dim strConnect, objRS, objComm
Set objComm = Server.CreateObject (&quot;ADODB.Command&quot;)
strConnect = &quot;Driver={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;.../report.mdb&quot;)&&quot;;&quot; &_
&quot;Persist Security Info = False&quot;

objComm.ActiveConnection = strConnect
objComm.CommandText = &quot;SELECT tblSurveyRawData.[MONTH/YEAR] FROM tblSurveyRawData GROUP BY tblSurveyRawData.[MONTH/YEAR]&quot;
objComm.commandType = adCmdText
Set objRS = objComm.Execute
%>
<select name=&quot;BeginQrtDate&quot;>
<option value=&quot;&quot;>Select an option</option>
<%
While (NOT objRS.EOF)
%>
<option value=&quot;<%=(objRS(&quot;MONTH/YEAR&quot;)%>&quot;><%=(objRS(&quot;MONTH/YEAR&quot;)%></option>
<%
objRS.MoveNext

Wend
%>
</select><br><br>
<%
objRS.Close
Set objComm = Nothing
Set objRS = Nothing
%>
 
Maybe it needs to be so:

<option value=&quot;<%=(objRS(&quot;[MONTH/YEAR]&quot;)%>&quot;><%=(objRS(&quot;[MONTH/YEAR]&quot;)%></option>
To err is human, but to really foul things up requires a computer.
- Farmers' Almanac, 1978

 
I try your method, but it still doesn't work.
 
1) Are you sure that your query returns results?
2) Is there an error message, or is the select box blank?

If you are sure that your query returns results and there is no error message, try this:

objComm.CommandText = &quot;SELECT tblSurveyRawData.[MONTH/YEAR] as TheDate FROM tblSurveyRawData GROUP BY tblSurveyRawData.[MONTH/YEAR]&quot;
objComm.commandType = adCmdText
Set objRS = objComm.Execute
%>
<select name=&quot;BeginQrtDate&quot;>
<option value=&quot;&quot;>Select an option</option>
<%
While (NOT objRS.EOF)
%>
<option value=&quot;<%=(objRS(&quot;theDate&quot;)%>&quot;><%=(objRS(&quot;theDate&quot;)%></option>
<%
objRS.MoveNext

Wend
%>
</select><br><br>
<%
objRS.Close
Set objComm = Nothing
Set objRS = Nothing
%>

Just in case ASP doesn't like the / character in field names.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top