Click to See Complete Forum and Search --> : Object required error


cs3mw
02-17-2009, 12:16 PM
Hi im new to asp coding so if anyone could help me with this it would be a great help. I have the following code

<!--#INCLUDE FILE="connection.asp" -->
<%

DIM objRS
dim strSql

Set objRS = Server.Createobject("ADODB.Connection")

objRS.open mydb
strSql = "INSERT INTO PollSubmit(PollID, rating) VALUES ('2', '" & Request.Form("rating") & "')"
objRS.Execute(strSql)

dim dbConn
dim strSql1
strSql1 = "SELECT COUNT(*) AS poll1 FROM PollSubmit WHERE PollID='2' AND rating='1'"
Set results1 = dbConn.Execute(strSql1)

'This section works out the number of users who have responded with choice 1 as a percentage. The multiplication by 4 is simply to make the bars look bigger
dim percentage1
dim width1

percentage1 = Round((results1("poll1")/200) * 100)
width1 = Round((((10/200) * 100)*4),0)

'This section works out the number of users who have responded with choice 2 as a percentage. The multiplication by 4 is simply to make the bars look bigger
dim percentage2
dim width2

percentage2 = Round((80/200) * 100)
width2 = Round((((80/200) * 100)*4),0)

'This section works out the number of users who have responded with choice 3 as a percentage. The multiplication by 4 is simply to make the bars look bigger
dim percentage3
dim width3

percentage3 = Round((20/200) * 100)
width3 = Round((((20/200) * 100)*4),0)

'This section works out the number of users who have responded with choice 4 as a percentage. The multiplication by 4 is simply to make the bars look bigger
dim percentage4
dim width4

percentage4 = Round((90/200) * 100)
width4 = Round((((90/200) * 100)*4),0)

%>

The error I am getting is located in the block of text in red and the error I am getting is

microsoft vbscript runtime error '800a01a8'
object required: "

/submitpoll.asp line 16

Any help would be greatly appreciated.

ryanbutler
02-17-2009, 02:48 PM
Double check your query works, either by response writing the variable that contains your sql or throw the query in your query analyzer.

And double check that you're getting data back from your first insert statement. Usually that error message means no data is being retrieved.

cs3mw
02-17-2009, 03:09 PM
Thanks Ryan but there is data in the table and the insert statement is working. Any other ideas? Im sure it is a syntax error but im unsure of where the error is.

Regards

Mike

cs3mw
02-17-2009, 03:49 PM
Hi I never declared the variable dbConn. A very silly error it seems.

ryanbutler
02-17-2009, 03:53 PM
Unless the code pasted is different that what you have, you declared the connection object, but glad you got it figured out. A helpful thing to ensure all variable are declared is to add:

<%option explicit%>

At the top of the page.

cs3mw
02-17-2009, 03:56 PM
Thanks for your words of avise I will take it on board for the future.
Regards