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

Why am I getting this "Object required: '' error

Status
Not open for further replies.

Soldano16

IS-IT--Management
Jul 19, 2002
11
CA
Here is the ASP code. I'm new at this. This is an example I copied from the internet. But I can't get it to work.


<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsAddComments 'Holds the recordset for the new record to be added
Dim strSQL 'Holds the SQL query to query the database

'Create an ADO connection object
Set adoCon = Server.CreateObject(&quot;ADODB.Connection&quot;)


'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;\soldano1616\db\guestbook.mdb&quot;)

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = &quot;SELECT tblComments.Name, tblComments.Comments FROM tblComments;&quot;

'Set the cursor type we are using so we can navigate through the recordset
rsAddComments.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsAddComments.LockType = 3

'Open the recordset with the SQL query
rsAddComments.Open strSQL, adoCon

'Tell the recordset we are adding a new record to it
rsAddComments.edit
rsAddComments.AddNew

'Add a new record to the recordset
rsAddComments.Fields(&quot;Name&quot;) = Request.Form(&quot;name&quot;)
rsAddComments.Fields(&quot;Comments&quot;) = Request.Form(&quot;comments&quot;)

'Write the updated recordset to the database
rsAddComments.Update

'Reset server objects
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing
Response.Redirect &quot; %>



Thanks in advance for any help offered.
Eric
 
one of your variables needs to have the set command in front of it, i dont know which one, but that is normally the case
 
I suspect tblComments because I see no definition for it and if you do not have OPTION EXPLICIT (you should) then tere will be no 'variable not defined' error. It would help to know on what line the error occurred.

Specify OPTION EXPLICIT.
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Sorry -

The error is line 18 per the server

Eric
 
You haven't instantiated your recordset. You need to do this before you attempt to set it's properties with:
Code:
Set rsAddComments = Server.CreateObject(&quot;ADODB.Recordset&quot;)

-Tarwn If your happy and you know it...
 
Thanks everyone - all better now.

I took the code from a tutorial on the net. That's sort of a mean trick to play on a newbie.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top