Form validation can be done in Javascript when a submit button is clicked. This is used to check the data entered into the current form. These checks deal with things like no data in required fields, non-numeric values in fields that must be numbers, conditions like if box A is checked then box B must not be checked and so forth. If the validation fails an alert box is displayed with advice about the problem and the form is not submitted.
After the form is submitted the data can be checked also. This can be for the same kinds of issues. Or additional issues involving comparing the submitted data to historical records and contextual information.
For example, the person has already picked 5 handles today, they can pick 6 handles or 6 cases but they cannot pick 5 handles, 5 cases, nor 5 knobs.
Programmer-types sometimes refer to the first kind of validation as client-side validation because Javascript runs on the persons computer, not on the web server. The second kind might be called server-side validation. An important point about the difference is that server-side validation can use information stored in databases, client-side validation does not have access to the database.
Your requirement sounds like you need to use server-side validation after the form is submitted. Therefore you need to add code to the ASP script to perform the validation and prepare the error message.
Here is an outline of the process.
Code:
<%
Dim msgError
'Variables used in query to build dynamic form
Dim strQueryPicks, rsQueryPicks
'Variables used in query to obtain history for a person
Dim strQuery, rsQuery, etc
Dim personid
...
If Request.Form("Submit") = "Store My Pick" Then
'Set up the ADODB stuff to query the database
...
'General form of validation query
strQuery = "SELECT part, measure FROM MyTable WHERE "
strQuery = strQuery & "personid = "
strQuery = strQuery & Request.Form("personid") & " AND "
strQuery = strQuery & "date_of_pick = CDate ( Now () ) "
'Execute the query to obtain a recordset with the data
' for this person on this day
...
'Loop through the recordset and compare the pick today
' with the history of picks.
msgError = ""
Do Until rsQuery.EOF
If rsQuery("pick") = Request.Form("pick") And
rsQuery("measure") = Request.Form("measure") Then
msgError = "Please enter a different measure.
End If
rsQuery.MoveNext
Loop
End If
...
'Existing code to store the submitted data.
'But first check whether there is a duplicate.
If Not msgError = "" Then
'Store the submitted data.
...
End If
...
'Existing code to build the dynamic form
personid = rsQueryPicks("personid")
%>
<html>
...
<h1>My Pick-of-the-Day</h1>
<div class="errormessage"><%= msgError %></div>
<form action="pick_of_the_day.asp">
<% 'Build dynamic form %>
<input type="submit" value="Store My Pick">
<input type="hidden" value="<%= personid %>">
</form>
...
</html>
What is happening here.
You will add a block of code at the top of your ASP script to perform the validation that involves previous picks. This block of code is the If Then ... End If block which I sketched above.
It starts by checking whether the form was submitted or not. When someone first goes to the page, pick_of_the_day.asp, there is no value for Request.Form("Submit") so the block is skipped. After submiting the form the block is executed.
The validation requires a new query of the database to obtain the historical values involved in the validation. This will be a second query different from the one used to build the dynamic form.
Then step through the recordset comparing each value to the submitted values. If everything is OK, the error message will remain blank. If a match is found the error message will be created. There is a place in the HTML to display the message on the page. It is always displayed but usually it is blank.
And finally do not store the submitted data if there was an error. Skip that code if the error message is not blank.
Note that you will need to loop through the form items also. My code does not do that. That loop can be inside the recordset loop, or outside, it doesnt really matter.
Also I am not terribly familiar with Access, so the condition on the date in the WHERE clause may not be correct.