Follow @dporton

Creating a TOM table within an interview

Recently the following question was asked in LinkedIn :

KG: Some years ago I saw an interview script that produced a TOM table and presented the information to the respondent. You might use this to show poll results when a respondent has answered a question. For the life of me I can not find that script. Does anyone have an example of this that I can use?

and it got the following response from

CB : I haven’t found the example, but here’s code to connect to a database and pull in the results. You’d need to adjust the code inside the If but I’m sure you could take that result and display it:

Dim rsquery, sSQL, oConnection, oRecordSet
Set oConnection = CreateObject("Adodb.connection")
Set oRecordset = CreateObject("ADODB.Recordset")

    oConnection.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=MyDatabase;Data Source=MyServer"
    sSQL = "Select * FROM [MyDatabase].[dbo].[MyTable]"

    Set rsQuery=oConnection.Execute(sSQL)
    If rsQuery.BOF=False Then'Found record(s)
        sampBusunit =cText(rsQuery.Fields["Busunit"])
    End if

This is a great reply as it shows one way , not using TOM , but a way that will work. If however you realy need to use TOM then you can do something like this once your table is created. To see how to create the table take a look at this post , but once you have your table object you can use the HTMLRenderer to do the rest for you.

Dim HtmlRenderer,sTomHTML

Set HtmlRenderer = CreateObject("ExportHtml.Renderer")
    HtmlRenderer.DisplayAnnotations = False
    HtmlRenderer.DisplayOption = 0              ' 0 = Table Only
    HtmlRenderer.EmbedCss = true
    HtmlRenderer.UseFormattedLabels = True
    HtmlRenderer.IncludeTitleBlock = False
    HtmlRenderer.IncludeTOC = False
    HtmlRenderer.OutputBodyOnly = True
    sTomHTML = replace(HtmlRenderer.Render(oTableDoc.GetTablesXml(sTable)),mr.newline,"")
    Set HtmlRenderer = Null

I do this sort of stuff all the time and it works well , I normally take the output data and run it through the Highcharts api. to produce charts etc. Oh and don’t forget this will only work in your survey if you have TOM on the server. To get an idea of what I do , take a look at this.

Leave a Comment

%d bloggers like this: