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.

Re: Error code help needed

If your goal is to add a record then you are going about it wrong. Select is used to query the database and return a record that is there.

To add a record you should use the Insert statement and check the return code to see if it added a record or you can use select to see if the record is there first and then if it is not there you could use either an Insert or you could use an RS.Addnew

The last code you posted is very hard to follow even after I added the code tags but I do not see any where a record is being added, I did see one place where it would try to update a record.

Re: Error code help needed

Originally Posted by DataMiser

If your goal is to add a record then you are going about it wrong. Select is used to query the database and return a record that is there.

To add a record you should use the Insert statement and check the return code to see if it added a record or you can use select to see if the record is there first and then if it is not there you could use either an Insert or you could use an RS.Addnew

The last code you posted is very hard to follow even after I added the code tags but I do not see any where a record is being added, I did see one place where it would try to update a record.

Hello ....and many thanks once again for your reply.....I am a bit confused myself now The database is being updated successfully and the code does add or remove the appropriate information. I don't know if I am providing you with the correct information for you to help me resolve the issue ?? The code does NOT however report a blank entry, but it still adds one to the .mdb with ) value. Apart from that the rest of the code works fine. There is a comment in the software that shows the section of code that should detect the invalid entry but it doesn't work.

The other part of the process is advising me that the 'new category' I have just added has been added to the database and whilst it DOES add the new category with a 0 Value, it does NOT advice me that any record has been added to the database. I hope that makes sense? I do have 3 .asp forms... 1 displays all categories in the .mdb, 1 ADDS new categories to the .mdb and 1 allows me to EDIT categories that are present in the .mdb these all work.

That code would update the data in a specific record if the record exists otherwise it would throw an error i.e. No current record

The same method can be used to add a new record but requires you to use the RS.AddNew method

From what you have posted I do not see any way that a new record would be added to the database unless I missed something. Is hard to read buried in with all the html code.

Could it be that you posted the code from the edit form rather than the add form?

Thanks again my friend.... I am no sure what I have done now .... confused?...but I will take all you have said and review each module carefully . I really hope I have supplied the correct code or I am going to be really embarrassed. I'll begin right now. Thanks again and ..... watch this spot...

Re: Error code help needed

Originally Posted by davida1956

Thanks again my friend.... I am no sure what I have done now .... confused?...but I will take all you have said and review each module carefully . I really hope I have supplied the correct code or I am going to be really embarrassed. I'll begin right now. Thanks again and ..... watch this spot...

This bit of code allows you to name a new category and attach a colour to that test, it then posts and populates the database. The following bit of code comes from the next bit of code come from the category_edit.asp file and should allow me to edit the category information...change the name and link colour, which it does but it doesn't seem to perform the test 'Check for empty field' and so doesn't throw out the error message show.

From category_edit.asp

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

This is supposed to check that the category that the correct data has been put into the field and report that a new record has been added to the database. This bit also doesn't work and I can't pin down which bit of code affects the other so that none of them perform at 100%. I don't know if this lot helps in any way or not ? It may only give you a bit of an sight but could point to a fault somewhere else? Is there anything else I can provide or do to try and pin the fault down please. Thanks again for your help

Re: Error code help needed

I still do not see anything there that would add a record. In fact there is nothing in that last post that would update a record either.

There are 2 basic ways to add a record to the database
1:

Code:

CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
CategoryRs.AddNew ' If you want to edit then you would omit this line
' some code to set the field values
CategoryRS.Update

Re: Error code help needed

I still do not see anything there that would add a record. In fact there is nothing in that last post that would update a record either.

There are 2 basic ways to add a record to the database
1:

Code:

CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
CategoryRs.AddNew ' If you want to edit then you would omit this line
' some code to set the field values
CategoryRS.Update

There is also a third method using parametrized queries. A quick search should turn up some examples.

Hi... thanks for the pointers, I think I have perhaps pinned down the code but cannot be sure of it. I have tried to describe what I think the code should do an....d associate lines of code from the 3 .asp pages

This next part of the script is from the … category_add.asp code which I think receives the information from the Category.asp Interface and posts it to the .mdb and the returns to the category.asp to display the result
The category.asp script also displays existing categories, which allows me the option to delete any of them and this part of the coding works.

For example
If I call for a new category …. ‘TEST’… the function follows the routine and adds the details to the database in the correct fields and in the correct format it also displays the new category on the ‘category.asp’ script, but does NOT display the message advising that the Category ‘TEST’ has been added to the database. I assume that the code to do this, which is shown below and copied from the above code, may not be correct ??
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then

End If
%>
{The category "<% Response.Write Request("TypeName")%>" has been added to the database.</p></td>}
If I enter a null value for the category name it still enters that data to the .mdb and displays it with (0) associated records. It also does not display the associated error message which is held in the category_add .asp code..At some point control is passed over to the category_add.asp module to be verified. I think this is the code it uses :-
CODE SECTION FROM -- CATEGORY_ADD.ASP
{
' *** Insert new category, name and link color:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
CategoryRS.AddNew
CategoryRS("TypeName") = Request("TypeName")
CategoryRS("TypeColor") =Request("LinkColor")
CategoryRS.Update
%>

There is only 1 other module associated with category issue and that is category_edit.asp. It gathers information from the two other modules and displays the information correctly (even if it is blank) I can then change the associated fields by adding, editing or removing, dates, details and categories. This seems to work fine. If the new category is still left empty then it still enters it back to the .mdb. I presume this is because the above section of code shown above has some sort of error? This is the code script from the category_edit.asp that I think looks for the conditions…

CODE SECTION FROM CATEGORY_EDIT.ASP

{
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then

but here you move off the page so that message will not be seen by the user

CategoryRS.Close()
Response.Redirect("category.asp")

Rather than having that redirect there you may want to consider adding an OK button or link that will go to the desired page when the user clicks on it and therefore allow the message to be displayed for the user to see.

but here you move off the page so that message will not be seen by the user

Rather than having that redirect there you may want to consider adding an OK button or link that will go to the desired page when the user clicks on it and therefore allow the message to be displayed for the user to see.

Hi again and thanks ever so much for pinpointing the problem, you make it sound so easy... you certainly are a Guru !! and this is some Forum... I am well impressed at the help you have offered and given freely to a fellow member... that news will travel. I will try to do as you suggest and let you know how it goes. I guess the same sort of procedure should be used to see the other advice / error message as well. OK... I will get stuck in now I have some spare time again... thanks a million my friend... David A

Re: Error code help needed

Originally Posted by davida1956

Hi again and thanks ever so much for pinpointing the problem, you make it sound so easy... you certainly are a Guru !! and this is some Forum... I am well impressed at the help you have offered and given freely to a fellow member... that news will travel. I will try to do as you suggest and let you know how it goes. I guess the same sort of procedure should be used to see the other advice / error message as well. OK... I will get stuck in now I have some spare time again... thanks a million my friend... David A

A little later.....Fantastic .. I followed you suggestion and simply added a hidden button. All information is still handed over to the .mdb correctly and the message approving it shown. The only issue left is that it doesn't detect the " " String value and trap it but also adds it to the database. The code I've shown below looks fine to me so I have no idea why it shouldnot work??Unless...... the value given is empty which it also still adds.

[
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then

Re: Error code help needed

You are trapping for an empty string so a string with one or more space will not be picked up by this.

If you want to also filter out strings that maybe be nothing but 1 or more spaces as well then you would use a trim() function

Code:

If Trim(Request("TypeName"))="" Then

Trim removes all spaces from the right and left of a string

Hi again and thanks a million for your reply. I do actually want to check for an empty string. If the field is empty then it should throw out an error message but it doesn't and the code looks fine to me so I am a bit confused.... I'm not too worried about padding or spaces in this section as only the 'admin' has access to it through the web interface, but Ican use that little gem you suggested in another function of the coding :-) any ideas?

Re: Error code help needed

In that case you just need to follow the code through from the point where the message is displayed by your code and see what it does after that. It is to hard to read it on here without code tags and proper indenting. Perhaps you have a redirect somewhere after the message that causes it to go to another page without actually giving the display like was the case in the add record part.

But then in your previous message you said

The only issue left is that it doesn't detect the " " String value

Which is not an empty string and will not be detected as one unless you trim the spaces off of it like I showed in my last post.

Re: Error code help needed

Originally Posted by DataMiser

In that case you just need to follow the code through from the point where the message is displayed by your code and see what it does after that. It is to hard to read it on here without code tags and proper indenting. Perhaps you have a redirect somewhere after the message that causes it to go to another page without actually giving the display like was the case in the add record part.

But then in your previous message you said

Which is not an empty string and will not be detected as one unless you trim the spaces off of it like I showed in my last post.

Hi again... Just got back to where I was a few days ago. I had to backtrack because whilst testing it out I found that things were corrupting the database and some scripts wouldn't run at all. I've spent a few days catching up with myself to the point where I have been trying to do the 'Trim' you explained. I assume I haven't done any damage as there is no fault in any of the modules right now. It still doesn't detect the empty string despite the trim and still adds "" to the category table. I am trying to trace my way through the rest of the code to see if I can spot a problem. It is a bit muddled up...mind you .. so am I ..... :-)