Trying to pull data from SQL database table: Microsoft VBScript runtime error '800a000d'

I just added some address fields to a table for events listings on this page here and I've called them in, but it's giving me the following error:

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'HTMLEncode'
/events.asp, line 125

I've created a test advert and it stored in the database so that's working, but I can't pull the data into the front end without it breaking the code.

Here's the code for the events listing pages with the bold bit being the additional fields I added and populated:

<!--#include virtual="/System/Startup_Public.asp"-->
If Session("PublicFranchiseGID") = "" then
    Response.Redirect "/"
End if

	sLink = "/" & lcase(session("publicfranchisename")) & "/events/index.html"
	sym = "?"
	if len(""&request.querystring("evtd"))>0 then 
	end if
	if len(""&request.querystring("evtc"))>0 then 
	end if
	if len(""&request.querystring("evtsd"))>0 then 
	end if
	if not sLink = request.ServerVariables("HTTP_X_REWRITE_URL") then
		response.status = "301 Moved Permanently"
		response.addheader "Location", "" & sLink
	end if


startdate = date()
if len(""&getquery("evtsd"))>0 then
	if isdate(getquery("evtsd")) then
		startdate = getquery("evtsd")
	end if
end if
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><%=server.HTMLEncode(Session("PublicFranchiseName"))%> Events, Essex, What's On in <%=server.HTMLEncode(Session("PublicFranchiseName"))%></title>
<meta name="Description" content="<%=server.HTMLEncode(Session("PublicFranchiseName"))%> Events and What's On in <%=server.HTMLEncode(Session("PublicFranchiseName"))%>, Essex" />
<meta name="Keywords" content="<%=server.HTMLEncode(Session("PublicFranchiseName"))%> Events, What's On <%=server.HTMLEncode(Session("PublicFranchiseName"))%>, Things to do in <%=server.HTMLEncode(Session("PublicFranchiseName"))%>" />
<link rel="stylesheet" type="text/css" href="/css/hot-sneaks/jquery-ui-1.8.22.custom.css"/>
<!--#include virtual="/Assets/Templates/Public/Franchise/HeadCSS.asp"-->
<link rel="stylesheet" type="text/css" href="/css/EventList.css"/>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.22.custom.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(e) {
			defaultDate: '<%=startdate%>',
			onSelect: function(dateText, inst) { $('#evtsd').val(dateText); }
<body id="events">
<!--#include virtual="/Assets/Templates/Public/Franchise/Events.asp"-->
	' default query, top 20 events on or after today
	limit = " TOP 30 "
	where = " AND (ca_enddate >= cast(GetDate() as date))"
	if len(""&getquery("evtsd")) >0 then
		if isdate(getquery("evtsd")) then
			sdate = year(getquery("evtsd")) & "-" & month(getquery("evtsd")) & "-" & day(getquery("evtsd"))
			if left(getquery("evtd"),1) = "p" then
				'where = where & " AND (ca_startdate BETWEEN '"&sdate&"' AND DATEADD(day,"&cint(replace(request.querystring("evtd"),"p",""))&",'"&sdate&"')) "
				where = where & " AND (ca_startdate < DATEADD(day,"&cint(replace(request.querystring("evtd"),"p",""))&",'"&sdate&"') AND "&_ 
												" ca_enddate > '"&sdate&"') "
				where = where & " AND (ca_startdate BETWEEN DATEADD(day,-"&cint(replace(request.querystring("evtd"),"m",""))&",'"&sdate&"') AND '"&sdate&"') "		
			end if
			limit = ""
		end if
	end if
	if len(""&getquery("evtc"))>0 then
		if isnumeric(getquery("evtc")) then
			where = where & " AND ca_category = "&cint(getquery("evtc"))
		end if
	end if
	sql = "SELECT "&limit&" *,dbo.RemoveNonAlphaCharacters(LTRIM(RTRIM(ca_title))) AS URL "&_ 
        "FROM CommunityArticles "&_ 
        "LEFT JOIN CommunityArticleCategories ON ca_category = cac_id "&_ 
        "WHERE ca_live = 1 AND ca_franchise = '{"&session("PublicFranchiseGID")&"}'	"&_ 
		where &_ 
		"ORDER BY ca_startdate ASC;"
    getrs rs,sql,""
	if rs.recordcount = 0 and len(""&limit)>0 then
		' no current events, fall back to archive listing
		sql = "SELECT TOP 20 *,dbo.RemoveNonAlphaCharacters(LTRIM(RTRIM(ca_title))) AS URL "&_ 
			"FROM CommunityArticles "&_ 
			"LEFT JOIN CommunityArticleCategories ON ca_category = cac_id "&_ 
			"WHERE ca_live = 1 AND ca_franchise = '{"&session("PublicFranchiseGID")&"}'	"&_ 
			"ORDER BY ca_startdate ASC;"
	end if
	if rs.recordcount > 0 then
    while not rs.eof 
    url = "/" & lcase(session("publicfranchisename")) & "/events/" & year(rs("ca_startdate")) & "/" & monthname(month(rs("ca_startdate"))) & "/" & server.URLEncode(rs("URL")) & ".html"
        <div class="event">
            <table width="100%" border="1">
                <td width="160" valign="top">
                    <% if len(""&rs("ca_thumbnail"))>0 then %>
                    <div class="event_image"><a href="<%=url%>"><img alt="<%=Session("PublicFranchiseName")%> events" src="/includes/tn.asp?src=/LiveStorage/Uploads/image/CommunityArticles/<%=server.URLEncode(""&rs("ca_thumbnail"))%>" 
                        alt="<%=server.HTMLEncode(""&rs("ca_title"))%>" /></a></div>
                    <% end if %>
                <td valign="top">
                    <h3><% if len(""&rs("cac_image")) > 0 then %><img alt="<%=Session("PublicFranchiseName")%> event category" src="/Assets/Images/EventCategories/<%=server.URLEncode(""&rs("cac_image"))%>" alt="<%=server.HTMLEncode(""&rs("cac_category"))%>" class="category" /><% end if %><a href="<%=url%>"><%=server.HTMLEncode(""&rs("ca_title"))%></a></h3>            
                    <h4>at <%=server.HTMLEncode(rs("ca_location"))%></h4>

[b]                    <h4>at <%=server.HTMLEncode(rs("ca_address1"))%></h4>
                    <h4>at <%=server.HTMLEncode(rs("ca_address2"))%></h4>
                    <h4>at <%=server.HTMLEncode(rs("ca_town"))%></h4>
                    <h4>at <%=server.HTMLEncode(rs("ca_county"))%></h4>
                    <h4>at <%=server.HTMLEncode(rs("ca_postcode"))%></h4>[/b]

                <td width="60" valign="top">
                    <div class="date">
                        <div class="month"><%=server.HTMLEncode(""&monthname(month(rs("ca_startdate")),true))%></div>
                        <div class="day"><%=server.HTMLEncode(""&day(rs("ca_startdate")))%></div>
                    <h4><a href="<%=url%>" class="button small silver"><span>View</span></a></h4>
    <% rs.movenext : wend 
	else %>
        <p>No events matched your query.</p>
	<% end if %>
<!--#include virtual="/Assets/Templates/Public/Franchise/TemplateEnd.asp"-->
<!--#include virtual="/System/Shutdown.asp"-->

Open in new window

Any help much appreciated.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Robert SchuttConnect With a Mentor Software EngineerCommented:
There is a quick and dirty trick for that:
<h4>at <%=server.HTMLEncode(rs("ca_address1") & "")%></h4>

Open in new window

(and for the other fields as well). This ensures that if a null value occurs in the data then it is silently converted to an empty string. A nicer way would be to use or make a function that checks for the null value and displays a message (if there are not supposed to be null values in the data).
UName10Author Commented:
Great, thanks for the reply.

I just tried it, but it's still the same unfortunately, can't understand why. It's fine to have null values and the table reflects that. It's a mystery..

It's pointing to the "Type mismatch: 'HTMLEncode'", but not sure why?

Thanks again.
Robert SchuttSoftware EngineerCommented:
Well, normally that would be the excact reason. HTMLEncode expects a string, but gets a null object and rejects it. The same trick I see is already used in the lines before:
<h3><% if len(""&rs("cac_image")) > 0 then %>

Open in new window

This is essentially the same, just the other way around, you could try that but shouldn't make a difference. Have you applied it to all lines? maybe also the one before (ca_location), sometimes the line numbering can be off.
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

UName10Author Commented:
Ahh no I'm sorry - it didn't save as I logged out! Just saw and readded it, now it's worked which is great.

How do I hide them if the fields aren't populated?

Many thanks again.
- removed solution -

didn't see they already posted something :)
UName10Author Commented:
Again sorry - it works. Nice solution, thank you.
Robert SchuttSoftware EngineerCommented:

To hide the empty parts you could do something like earlier in the code:
<% if len(""&rs("ca_address1")) > 0 then %>
<h4>at <%=server.HTMLEncode(rs("ca_address1"))%></h4>
<% end if %>

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.