title: ASP Object required
body: <p>I have the error in Classic ASP:</p>
  
  <pre><code>Microsoft VBScript runtime error '800a01a8'
  Object required: 'SqlStatement'
  /Data/Database.asp, line 186 
  </code></pre>
  
  <p>The line 186 is: <code>SqlStatement.CommandText = sql</code>.</p>
  
  <p>Here is my code:</p>
  
  <pre class="lang-vbs prettyprint-override"><code>Dim Db, SqlStatement, RS
  Set Db = Nothing
  Set SqlStatement = Nothing
  Set RS = Nothing
  
  ' Initialize the database once
  Private Sub SqlInitDb()
      If isNull(Db) Or varType(Db) = vbEmpty Or IsObject(Db) = False Then
          ' Create database connection object
          Set Db = Server.CreateObject("ADODB.Connection")
          ' Set connection timeout
          Db.ConnectionTimeout = Session("ConnectionTimeout")
          ' Set command timeout
          Db.CommandTimeout = Session("CommandTimeout")
          ' Open database
          Db.Open Session("ConnectionString")
      End If
  
      If isNull(SqlStatement) Or varType(SqlStatement) = vbEmpty Or IsObject(SqlStatement) = False Then
          ' Create a sql statement
          Set SqlStatement = Server.CreateObject("ADODB.Command")
          ' Set opened database as active connection for the SQL statement
          SqlStatement.ActiveConnection = Db
      End If
  End Sub
  
  ' Close the database if it is not closed
  Private Sub SqlClose()
      If Not isNull(SqlStatement) And varType(SqlStatement) &lt;&gt; vbEmpty And IsObject(SqlStatement) = True Then
          SqlStatement.ActiveConnection.Close
      End If
  
      Set SqlStatement = Nothing
  
      If Not isNull(Db) And varType(Db) &lt;&gt; vbEmpty And IsObject(Db) = True Then
          For Each objErr In Db.Errors
            response.write("&lt;p&gt;")
            response.write("Description: ")
            response.write(objErr.Description &amp; "&lt;br&gt;")
            response.write("Help context: ")
            response.write(objErr.HelpContext &amp; "&lt;br&gt;")
            response.write("Help file: ")
            response.write(objErr.HelpFile &amp; "&lt;br&gt;")
            response.write("Native error: ")
            response.write(objErr.NativeError &amp; "&lt;br&gt;")
            response.write("Error number: ")
            response.write(objErr.Number &amp; "&lt;br&gt;")
            response.write("Error source: ")
            response.write(objErr.Source &amp; "&lt;br&gt;")
            response.write("SQL state: ")
            response.write(objErr.SQLState &amp; "&lt;br&gt;")
            response.write("&lt;/p&gt;")
          Next
          Db.Close()
          Set Db = Nothing
      End If
  End Sub
  
  ' Insert a user to the database
  Public Function InsertUser(ByVal userObj)
      If isNull(userObject) Or varType(userObject) = vbEmpty Then
          InsertUser = -1
          Exit Function
      End If
      Call SqlInitDb()
      Set RS = Server.CreateObject("ADODB.Recordset")
  
      Dim sql
      sql = "INSERT INTO users(Firstname,Surname) VALUES ('"&amp;userObj.getFirstname()&amp;"','"&amp;userObj.getSurname()&amp;"')"
      SqlStatement.CommandText = sql
      SqlStatement.CommandType = 1
  
      ' Run the insert statement
      SqlStatement.Execute
      InsertUser = Err.Number
      Call SqlClose()
  End Function
  </code></pre>
  
  <p>SqlStatement is clearly an object so I don't understand.</p>
  
  <p>Thanks</p>