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!

Adding a record from a list box to a DB

Status
Not open for further replies.

kaycee79

Technical User
Jan 10, 2004
82
GB


I am trying to add a record from a list box to the database, but an error message
appears;

Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/new/addreporttodb.asp, line 22

Line 22 is

objRS.Fields("EventName") = Request.Form("txtEventName")

Can any help me on this?

Thanks in Advance

This is the code that i am using

Input Form
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">



<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
<FORM ACTION = "addreporttodb.asp" METHOD= "post">

<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>




<P>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 %>


</form>
</body>
</html>

Code to add data to DB

Code:
<!-- #include file="ProjectConnection.asp" -->

<!-- METADATA TYPE="typelib"
              FILE="c:\Program Files\Common Files\System\ado\msado15.dll" -->

<%
	Dim strConnect
%>
<html>
<head>
<title>Add Report</title>
</head>
<body>
<%

	Dim objRS
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open "EventReport", strConnect, adOpenKeySet, AdLockOptimistic
	objRS.AddNew
	objRS.Fields("EventName") = Request.Form("txtEventName")
	objRS.Fields("Date") = Request.Form("txtDate")
	objRS.Fields("Report") = Request.Form("txtReport")
	objRS.Fields("Username") = Session("Username")
	
	objRS.Update
	objRS.Close
	Set objRS = Nothing

	Response.Redirect "eventreportconfirmation.asp"
%>
</body>
</html>
 
Try a little step by step debugging on this. Make sure your field name is spelled correctly. Comment out te offendind line and see if the rest work. If the rest work but that one line doesn't then we will concentrate on that. If the rest don't work either then we have a larger problem to concentrate on.

-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