title: vbscript display a database query in html table
body: <p>I've seen several examples, but all are in ASP or PHP. The company I work for has a lot of security and I'm not allowed to install either of these on my computer for development, therefore, I need to do this in HTML.</p>
  
  <p>I created a form that gathers info from the user and submits it, via VBScript, to a 2010 Access Database. What I need to figure out is how to display this in an HTML table.</p>
  
  <p>Here's the VBScript sub that queries the database for everything in the table:</p>
  
  <pre><code>Sub SelectFromDatabase()
  
      Dim strSQL, strConnect
  
      Dim conn, rs
  
      Set conn = CreateObject("ADODB.Connection")
  
      strConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\My Stuff\MyData.accdb;Persist Security Info=False;"
  
      conn.Open strConnect
  
      strSQL = "SELECT * FROM SurveyData"
  
      ' Send the query to the database and save result
      Set rs = conn.Execute strSQL
  
      ' Close the connection to the database
      conn.Close
      strSQL = ""
  
  end sub
  </code></pre>
  
  <p>I created a separate sub that calls the previous sub and stores the data in variables:</p>
  
  <pre><code>sub PrintData
      call SelectFromDatabase()
      strFullName = FullName
      strAddress = Address
      strCity = City
      strState = State
      strZip = Zip
      strPhone = Phone
      strEmail = Email
      strComputer = Computer
      strOS = OS
      strShopping = Shopping
  end sub
  </code></pre>
  
  <p>This is the HTML that I'm using to print the data to an HTML table:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;My Web Site - Customer Data&lt;/title&gt;
          &lt;script language="vbscript" type="text/vbscript" src="Process.vbs"&gt;
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body onLoad="SelectFromDatabase();"&gt;
          &lt;h1 align=center&gt;My Web Site&lt;/h1&gt;
          &lt;h2&gt;Customer Data&lt;/h2&gt;
          &lt;p&gt;Below is a list of the customer data that has been submitted.&lt;/p&gt;
          &lt;hr&gt;
          &lt;script language="vbscript" type="text/vbscript"&gt;
              document.writeln("&lt;table border=1&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Address&lt;/th&gt;&lt;th&gt;City&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;th&gt;Zip&lt;/th&gt;&lt;th&gt;Phone&lt;/th&gt;&lt;th&gt;Email&lt;/th&gt;&lt;th&gt;Computer&lt;/th&gt;&lt;th&gt;OS&lt;/th&gt;&lt;th&gt;Shopping&lt;/th&gt;&lt;/tr&gt;")
              Do Until rs.EOF
                  document.writeln("&lt;tr&gt;&lt;td&gt;" &amp; rs(0) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(1) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(2) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(3) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(4) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(5) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(6) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(7) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(8) &amp; "&lt;/td&gt;&lt;td&gt;" &amp; rs(9) &amp; "&lt;/td&gt;&lt;/tr&gt;")
                  rs.MoveNext
              Loop
              document.writeln("&lt;/table&gt;")
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The error I'm getting is in the <code>for each...</code> row. It is saying that <code>PrintData</code> is not a collection, which I agree, but I'm not sure now I would call the sub <code>PrintData</code> and be able to use the info in an HTML table.</p>