[RESOLVED] Error code help needed
Hi Folks.. I am a real newbie to this... no real knowledge about programming but keen to learn. I am playing with some code at the moment that should return a message that a 'category' has been added to an Access Database and another bit checking to see that if a no value is entered it writes an error message. I can't get the **** thing to work and think I may have tried to run before I can walk. saying that if there are no values. The error message I get is ...
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'TypeId ='.
it makes reference to line 67 in the code but I can't find anything there that may be wrong
and the code I am using is
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Else
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
%>
Sorry for being such a thicko but can anybody out there please help me ???
thanks to you all who take an interest in these and help us newbies sort things out.....
Regards
David A
Re: Error code help needed
What value is in iType?
Is TypeID a text field or numeric field in the db?
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
What value is in iType?
Is TypeID a text field or numeric field in the db?
Hi and thank you so much for a prompt reply I really appreciate it. Here is a copy of what the .mdb file holds.
TypeId TypeName TypeColor
966 BOOKED #F00
968 Enquiries #CCC
973 MDA #00F
977 TEST #000
I'm keen to try and learn so any pointers and advice you can give would be great. This is even my first attempt at joining a forum! I was made redundant so have to find something to fill my time in otherwise go mad.
Regards
David A
Re: Error code help needed
Re: Error code help needed
Unfortunately you did not answer either of my questions.
I assume based on the data and field name that TypeID is a numeric field but I can only guess since you did not say.
You also did not say what value is held in iType
My guess would be that it is empty and that would trigger an error with a numeric field type.
Re: Error code help needed
Hi DataMiser.... sorry but am still finding my way around .. TypeID is a numeric value held in my .mdb and looks like this
TypeId TypeName TypeColor
966 BOOKED #F00
968 Enquiries #CCC
973 MDA #00F
977 TEST #000
The code does actually enter the the record but does not confirm it has done so nor does it confirm the action of deleting the record.
I not I need to use [ ] to show code so here is my first shot at it
Code:
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Else
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
%>
if that doesn't work can you please let me know :-) Thanks 100 %
David A
Re: Error code help needed
You still did not tell us what value is in iType when the code is executed,
Quote:
WHERE TypeId =" & Request("iType")
If iType is blank you will get an error
Also you told us the field in the db contains numeric data but we could already see that, the question was is the field a numeric field. Numeric fields can only contain numbers, text fields can contain numbers as well so having numeric data does not always mean the field is numeric but I will assume that it is.
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
You still did not tell us what value is in iType when the code is executed,
If iType is blank you will get an error
Also you told us the field in the db contains numeric data but we could already see that, the question was is the field a numeric field. Numeric fields can only contain numbers, text fields can contain numbers as well so having numeric data does not always mean the field is numeric but I will assume that it is.
Hi and thanks so much for your patience with me and of course the speedy reply. Please bare with me as I'm on a rapid learning curve... Yes the TypeId field is defined as being a numeric auto-increment field which I guess is right. As for the iType I'm struggling to answer that. What should happen is if the field is left empty you should get the error message advising of that and be prompted to input a value. If a value is given then I presume it is called iType and a message advising that 'the data given' has been added to the database. Neither messages work but the information is still passed to the database. I think I understand how it should work but just don't have the skills yet to debug the software. Is this of any help and if not is there anything else I can do to help understand the problem at both ends of the spectrum... Newbie-----Expert... Again... thanks a million guys
David A
Re: Error code help needed
Your code checks to see if typename is an empty string if it is then it displays a message if it is not then it executes a select statement which uses iType as a where clause but your script does not test the value of iType so it would process it no matter what the value or lack of a value and looks to be the cause of the error. See the lines in Red
Code:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Else
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
I am assuming that this is a server side ASP script and that iType is the name of an object that is on a form that been posted?
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
Your code checks to see if typename is an empty string if it is then it displays a message if it is not then it executes a select statement which uses iType as a where clause but your script does not test the value of iType so it would process it no matter what the value or lack of a value and looks to be the cause of the error. See the lines in Red
Code:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Else
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
I am assuming that this is a server side ASP script and that iType is the name of an object that is on a form that been posted?
Hi and once again many thanks for your reply. You are bang on with the understanding that this is a server side .asp script. It uses an admin panel to update, add or edit given categories. I have checked through things and noted that even when you enter a "" value the category is added to the database with the default colour of black. None of the other fields contain information. iType is a value held in one of the fields labelled EventType in the .db which contains a value of "0" when entered without a category name. I though that if the category had not been named then the code should have returned an error message and not updated the .db with a prompt to correct it. If I try to access this .db through my browser then I am able to see that the error points to a value with iType. What I don't understand is how to check for an invalid entry when the code to do it is there. Do I need to modify the code or the .db? As mentioned... newbie struggling with basics here :-( thanks so much for your help so far, very commendable and forums seem to be the place to get expert help, reassuring to know there is somebody out there that takes an interest in newcomers.:thumb: I'm going to get stuck into the code again and try to understand what it is doing, where and when. Maybe I can insert some form of debugging script in to pinpoint what I need to do and where ???
regards
David A
Re: Error code help needed
An autonumber field populates automatically when you add a record. You can not select using a numeric field in a where clause without a valid numeric value as part of that clause.
to test it you could use IsNumeric()
Code:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
Else
' display some message stating that the type id is not valid
End If
Or maybe you need to change the select statement to use the TypeName instead, just depends on what you want it to return. TypeID should never return more than 1 record, TypeName may return more than one depending on your data
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
An autonumber field populates automatically when you add a record. You can not select using a numeric field in a where clause without a valid numeric value as part of that clause.
to test it you could use IsNumeric()
Code:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
Else
' display some message stating that the type id is not valid
End If
Or maybe you need to change the select statement to use the TypeName instead, just depends on what you want it to return. TypeID should never return more than 1 record, TypeName may return more than one depending on your data
Hi and thanks again for your reply........eeeerrrrmmmm yes.... it will take me a little while to digest that little gem but will try my best and let you know. It's all a little alien to me right now... sorry for being such a pain :blush:
Re: Error code help needed
Quote:
Originally Posted by
davida1956
Hi and thanks again for your reply........eeeerrrrmmmm yes.... it will take me a little while to digest that little gem but will try my best and let you know. It's all a little alien to me right now... sorry for being such a pain :blush:
Hi... I'm back again to bother you .... I tried what you suggested as shown below but it made no difference. When I add blank data as the category it doesn't trap it nor does it warn me so there is no error message. The data is however written to the database. When I try to edit it from the web console Explorer displays the message
/calendar/admin/category_edit.asp?iType=973 and displays ...error cannot display the page... Apart from this problem I have just about tweaked the code to do what I want, showing information I want, where I want and in the correct format and font
the database does however have a data Type field which does have the entry 973. This is what I modified. I'm not sure how to replace variable and what they should be. I know this is only a smallpart of the code, could there be something I am not including for you to pinpoint the problem perhaps?
[
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' If Flag isn't true, show the edit form:
Dim CategoryRS
Else
Response.Write " You must enter a details for this to work"
' display some message stating that the type id is not valid
End If
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
%>
]
I have a banging head now so will lay off for a few hours before going back again to tidy up some other details. I look forward to your reply ....Thanks :blush::wave:
Re: Error code help needed
Your If block is all messed up.
If TypeName="" Then
'code here will only execute if the typename is empty
End If
so if typename is not empty none of the code will execute will execute
I did not notice that second embedded If statement before not sure what its purpose is
Here I have commented out that If statement that tests flag. You should get different results
Code:
If Request("TypeName")="" Then
'If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
Else
' display some message stating that the type id is not valid
End If
Since I do not know what flag is or why you are testing for a blank name and then for flag I can't say how it should be to get your desired results but know that in your last post if typename not = "" then none of the following code will execute and will jump straight to the end if at the bottom
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
Your If block is all messed up.
If TypeName="" Then
'code here will only execute if the typename is empty
End If
so if typename is not empty none of the code will execute will execute
I did not notice that second embedded If statement before not sure what its purpose is
Here I have commented out that If statement that tests flag. You should get different results
Code:
If Request("TypeName")="" Then
'If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
Else
' display some message stating that the type id is not valid
End If
Since I do not know what flag is or why you are testing for a blank name and then for flag I can't say how it should be to get your desired results but know that in your last post if typename not = "" then none of the following code will execute and will jump straight to the end if at the bottom
Thanks for your reply once again. I've got to give you 100% for trying to help and persevering with me my friend. I don't know if I can answer you questions fully but here goes. The project is a calendar system that I can use to display events through out the year. thy can be either single day evens or events that span a few weeks. I can add, delete or modify events without any problems. Part of the software allows me to create categories with associated colours that are displayed on the calendar page so for instance I could add new categories such as 'meetings', 'appointments' and holiday. When I add an event I can enter it under a category which is then displayed on the calendar day it is associated with. If I click on the event it will then provide me with all details I have entered when it was submitted. I should not be able to enter a new category without an associated name because it wouldn't make sense. I thought the code would check to make sure that I had given this new category a name and if not, reject the request with the error message. At the same time if I enter a valid category that meets with the conditions, it should advise me that the 'new' category has been added to the database. I'm not sure what all the variable do yet and if I can even trace them. I have posted the complete .asp file below just in case it helps you follow my thinking. You will obviously be able to make much more sense of it than me....
Code:
{
<% @EnableSessionState=True %>
<% Option Explicit %>
<%
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
%>
<% If Request.Cookies("AppLoggedIn") <> "True" Then Response.Redirect("default.asp")
If Request.Cookies("Admin") <> "True" Then Response.Redirect("default.asp") %>
<!--#include file="../Connections/conncalendarAdmin.asp" -->
<html>
<head>
<title>Calendar Admin Category Edit</title>
<link href="../assets/calendar.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
background-color: #30F;
margin-top: 50px;
}
</style>
</head>
<body>
<div align="center">
<table width="760" border="0" cellspacing="2" cellpadding="0">
<tr>
<td><div align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#003399">
<tr>
<td bgcolor="#000">
<div class = "links">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="18" align="left" valign="middle" bgcolor="#FFE5B2" class="textBold"> <strong>
<a href="events.asp">EVENT LISTING</a> | <a href="submit.asp">ADD NEW EVENT</a> | <a href="purge.asp">PURGE OLD EVENTS</a> | <a href="category.asp">EDIT CATEGORIES</a></strong></td>
<td align="right" valign="middle" bgcolor="#FFE5B2" class="textBold"><div align="center"><A HREF="logout.asp"><strong>LOGOUT</strong></A> </div></td>
</tr>
</table>
</div>
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then
'If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
Else
' display some message stating that the type id is not valid
Response.Write "<p class='subtitle'>I must have an error here somewhere...</p>"
End If
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td align="left" valign="middle"><p> </p><form method="POST" action="<%= Request.ServerVariables("URL") %>" name="ADD">
<table align="center" class="textBold">
<tr valign="baseline">
<td nowrap align="right" valign="middle">EDIT CATEGORY NAME:</td>
<td> <input name="TypeName" type="text" class="form" value="<%=CategoryRS("TypeName")%>" size="50" maxlength="50">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="middle">CATEGORY LINK COLOR:</td>
<td> <select name="LinkColor">
<%
Dim LinkColorRS
Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
LinkColorRS.Open "SELECT * FROM LinkColor", Connect, 3, 3
While (Not LinkColorRS.EOF)
Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'"
If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Response.Write "selected"
Response.Write">" & LinkColorRS("ColorName") & "</option>"
LinkColorRS.MoveNext
Wend
LinkColorRS.Close()
CategoryRS.Close()
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td> <input name="Submit" type="submit" class="form" id="Submit" value="Submit">
</td>
</tr>
</table>
<input type="hidden" name="Flag" value="True">
<input type="hidden" name="TypeId" value="<%=Request("iType")%>">
</form>
<%
' If the form has been submitted (Flag = True), and the Category Name field isn't empty, update the record:
Else
Dim TypeRS
Query = "SELECT * FROM Type WHERE TypeId=" & Request("TypeId")
Set TypeRS = Server.CreateObject("ADODB.Recordset")
TypeRS.Open Query, Connect, 2, 3
TypeRS("TypeName") = Request("TypeName")
TypeRS("TypeColor") = Request("LinkColor")
TypeRS.Update
TypeRS.Close()
Response.Redirect("category.asp")
End If
%></td>
</tr>
<tr>
<td align="center" valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div></td>
</tr>
</table>
</div>
<div align="center"></div>
</body>
</html>
}
did it help any :confused: thanks one once again. you guys provide one hell of a service to the community....