If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[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.....

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.

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

Last edited by davida1956; June 9th, 2013 at 01:00 PM.
Reason: Improved ata

Re: Error code help needed

You still did not tell us what value is in iType when the code is executed,

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

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

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

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. 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 ???

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

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

Re: Error code help needed

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

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

Re: Error code help needed

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

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....