Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch Error

Status
Not open for further replies.

foundsheep

Programmer
Jan 24, 2008
12
US
I have a drop down list that is being populated by a database, and it is throwing an 800a000d Type Mismatch error. Here is the line of code the error occurs on:

<option value="<%=rsCus("cusID")%>" <%if CInt(rsCus("cusID")) = CInt(d) then%> selected<%end if%>><%=rsCus("Company")%></option>

Here's the entire form:

<form name="frmDisp" action="dispatch.asp?action=addDisp2" method="post">
<table cellSpacing="0" cellPadding="3" width="800" border="0" class="main_table">
<tr>&nbsp;
<td BGCOLOR="silver" class="table_Header" colspan="2">ADD DISPATCH</td>
</tr>
<tr>
<td width="15%">Company:</td>
<td>
<select id="company" name="company" onChange="this.form.submit()">
<option>Choose . . .</option>
<%
call openConn()
Dim d
d = Request("company")
Set rsCus = Server.CreateObject("ADODB.Recordset")
rsCus.Open "SELECT * FROM Customer", db, 3, 3, 1

Do Until rsCus.EOF
Dim c
c = rsCus("cusID")
%>
<option value="<%=rsCus("cusID")%>" <%if CInt(rsCus("cusID")) = CInt(d) then%> selected<%end if%>><%=rsCus("Company")%></option>
<%
rsCus.MoveNext
Loop
%>
</select>
</td>
</tr>
<tr>
<td width="15%">Equipment:</td>
<td>
<%
Set rsCon = Server.CreateObject("ADODB.Recordset")
rsCon.Open "SELECT * FROM Serviced_Equipment WHERE cusID = " & Request("company"), db, 3, 3, 1
%>

<%
if not rsCon.EOF then
%>
<select id="equipment" name="equipment" onChange="updateField()">
<option>Choose . . .</option>
<%
Do Until rsCon.EOF
%>
<option value="<%=rsCon("conID")%>"><%=rsCon("Description")%></option>
<%
rsCon.MoveNext
Loop
%>
</select>
<%
else
%>
Choose Company With Equipment
<%
end if
call closeConn()
%>
</select>
</td>
</tr>
</form>

 
Try this....

Code:
Do Until rsCus.EOF
    Dim c
    c = rsCus("cusID")
    
    cSeleted = ""
    If IsNumeric(d & ".0e0") Then
		If cLng(rsCus("CusId")) = cLng(d) Then
			cSelected = "selected=""selected"""
		End If
	End If
    %>
    <option value="<%=rsCus("cusID")%>" <% =cSelected%>><%=rsCus("Company")%></option>
    <%
    rsCus.MoveNext
Loop

If this works for you, and you'd like me to explain, just let me know.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Oh yeah... I forgot to mention...

Do yourself a favor and 'never use cInt() again'. The reason is simple. An integer maxes out at 32,000 (+ change). Instead, use cLng which converts to a long instead of an int.

It may be a long time before this problem ever occurs for you, but a simple change now could save you a lot of headaches later.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks, I have a couple more issues. One is if you happen to go back and select the option "Choose..." after you've selected a database item it throws this error:

Microsoft JET Database Engine error '80040e14'

Syntax error in query expression 'cusID = Choose . . .'.

/modules/dispatch/disFunctions.asp, line 183


which refers to this line of code:


rsCon.Open "SELECT * FROM Serviced_Equipment WHERE cusID = " & Request("company"), db, 3, 3, 1
 
Your original problem, and this problem are similar.

Request("company")

You are treating that as though it ALWAYS contains a valid number. To correct this problem, you should check to make sure it is a number before you use it.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I see what you are saying I just don't know how to do it. Does this statement need to be changed or something else?

rsCon.Open "SELECT * FROM Serviced_Equipment WHERE cusID = " & Request("company"), db, 3, 3, 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top