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

List Box problems

Status
Not open for further replies.

kaycee79

Technical User
Jan 10, 2004
82
GB
List Box

I have the code below, which is supposed to populate a list box with
records from the database; if there are not records, then a message is produced,
this works fine, but when there is multiple records in the database,
it has a list box for each seperate record.

I can not seem to find the problem, can anyone help please?

Thanks in advance

Code:
<%
Option Explicit
Dim StrConnect
%>

<!-- #INCLUDE FILE="ProjectConnection.asp" -->
<!-- #INCLUDE FILE="clock.inc" -->

<HTML>
<HEAD>
<TITLE>Add Event Report</TITLE>
</HEAD>
<BODY>
<body bgcolor="#99CCFF">
<font face="Arial">
<form name="theClock" action="addreporttodb.asp" method="post">
    
    <input type=text name="theTime" size=6><% Response.Write Date %><br>


<center><u><b><font size="7">Add an Event Report</font></center></b></u></p>

<BR>
<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Events", strConnect, 3,3
If objRS.BOF and objRS.EOF Then
Response.Write "There are no events to write reports on"
Else
objRS.MoveFirst
Do While Not objRS.EOF
%>

Event Name

<SELECT NAME="txtEventName" SIZE="1">

<%
Response.Write "<OPTION VALUE='" & objRS("EventName") & "'>"
Response.Write objRS("EventName") & "</OPTION>"
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
%>
</SELECT>

Date<input type="text" name = "txtDate" size="20"><BR>
Report<BR> 
<textarea name="txtReport" col="200"  rows="12" wrap="virtual" cols="40"></textarea> <BR>
<BR>

<INPUT TYPE="SUBMIT" VALUE="Submit"><BR>

<% End If %>

</font>
</form>
</body>
</html>
 
You have the code for building the listbox INSIDE your loop. This should be outside. Try this:
Code:
<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Events", strConnect, 3,3

If NOT objRS.EOF Then
  Response.Write "Event Name<BR><BR><SELECT NAME='txtEventName' SIZE='1'>" & vbcrlf

  While NOT objRS.EOF
    Response.Write "<OPTION VALUE='" & objRS("EventName") & "'>" & objRS("EventName") & "</OPTION>" & vbcrlf
    objRS.MoveNext
  Wend

  Response.Write "</SELECT>" & vbcrlf
Else
    Response.Write "There are no events to write reports on"
End If

objRS.Close
Set objRS = Nothing
%>

Date<input type="text" name = "txtDate" size="20"><BR>
Report<BR> 
<textarea name="txtReport" col="200"  rows="12" wrap="virtual" cols="40"></textarea> <BR>
<BR>

<INPUT TYPE="SUBMIT" VALUE="Submit"><BR>

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
thanks for that, it works, but the problem is that
then there is no records in the database, and the message appears
stating that there are no events to report on, the date and report
input boxes are still there, and i dont want this, i want just the message
and no other input boxes or buttons

Can anyone help?

thanks in advance
 
Just move the Date and whatever lse to the first part of the If satment so they will only be diplayed when there are records to be displayed in the Select.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top