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!

Validation Problem

Status
Not open for further replies.

slr22

MIS
Jun 26, 2002
80
0
0
US
I'm having some problem with my validation. The page that I'm doing the validation on is a page where I add a new line to the table in the database. I enter in a date field so I want to make sure that they are entering in a valid date. I use the following code:

Sub thisPage_onenter()

if (thisPage.firstEntered) then
Recordset1.addRecord()
end if
end Sub

Sub btnSubmit_onclick()

dim errmsg

OktoProcess=false

if txtDate.value <> &quot;&quot; and IsDate(txtDate.value) = false then
errmsg = &quot;Quote Due Date is a date field. Please enter the date in the format mm/dd/yyyy&quot;
else if txtProjDate.value <> &quot;&quot; and IsDate (txtProjDate.value) = false then
errmsg = &quot;Project Start Date is a date field. Please enter the date in the format mm/dd/yyyy&quot;
else
OktoProcess = true
end if
end if

if (OktoProcess=false) then
Response.Write &quot;<font size=4 color=red>&quot; & errmsg & &quot;</font>&quot;
else
Recordset1.updateRecord
Response.Redirect (&quot;MainMenu.asp&quot;)
end if
End Sub

I have this exact same code in another web application and it works just fine. However, with this one it seems to forget about the adding a new line and just updates the first line in the table. If I enter in a correct date and it skips having the output an error message, it works fine. Does anyone know why this might be doing this? Any help would be appreciated.

Thanks.
 
Looks like and extra end if in this block

if txtDate.value <> &quot;&quot; and IsDate(txtDate.value) = false then
errmsg = &quot;Quote Due Date is a date field. Please enter the date in the format mm/dd/yyyy&quot;
else if txtProjDate.value <> &quot;&quot; and IsDate (txtProjDate.value) = false then
errmsg = &quot;Project Start Date is a date field. Please enter the date in the format mm/dd/yyyy&quot;
else
OktoProcess = true
end if
end if
 
Every if or else if needs to end with a end if. If I had an extra end if it would give me an error message telling me so and woulnd't do what it is doing.

 
It should be &quot;elseif&quot; not &quot;else if&quot; and pull the extra end if. so the way you have it evals the first if as true is done.

This is a simplified version of what you have. As it would be interpreted by asp

if .... then
errmsg = &quot;...&quot;
else
if txtProjDate.value <> &quot;&quot; .... then
errmsg = &quot;......&quot;
else
OktoProcess = true
end if
end if

verse what you want to have happen.

if .... then
errmsg = &quot;...&quot;
elseif txtProjDate.value <> &quot;&quot; .... then
errmsg = &quot;......&quot;
else
OktoProcess = true
end if

hth
 
Ok I always thought that it was else if. It works either way, but I like your way better, it is much cleaner looking.

However it still doesn't solve my problem. It goes though and checks to make sure that they have entered in a correct date, which it does correctly. My problem is that when it goes through this validation it doesn't add the record it updates. Instead of adding a record, it puts the values that I entered into the first record in the table. It looks at the first record and updates whatever was in that record with what I entered in the field.
 
Unfortunately the recordset DTC does not 'remember' the fact that it is in AddRecord mode between server round trips. If you validate on the server, it does a server round trip - and then the Recordset repositions to the first record.

You can adjust the DTC code to correct this fault (and a number of other issues).

Or you could use the AddImmediate, rather than a simple Update to cause the new record to be stored to the database.

Or you could set each textbox etc. to be un-bound from the Recordset (just leave the column name blank). Then you can use any number of methods to Add the data to the database - its just a bit more typing. The downside is that the page does not easily support Updates.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top