Hi all,

I have a three fields, Age, Adults, and Children, I have been able to calculate the age from the Date of Birth input, however, what I seem not to succeed on is to have the text value "Adult" automatically entered in to the [Adults] field if the Age value is Grater than 16 and text Value of "Child" in the [Children] field if the Age value is less than or equal to 16.

Any help is highly appreciated.

Cheers

Best to post your code if you want us to look for errors.

Hi,

Here is the querry that is used for the fields, I don't know wheather this would help....

Regards,

Erick

SELECT
[Dependants Details].DependantID,
[Dependants Details].Name,
[Dependants Details].Contact,
[Dependants Details].Reationship,
[Dependants Details].StaffID,
[Dependants Details].Date_of_Birth,
[Staff Details].Staff_Name,
DateDiff('yyyy',[Date_of_birth],Now())+Int(Format(Now(),'mmdd')<Format([Date_of_birth],'mmdd')) AS Age,
[Dependants Details].Adults,
[Dependants Details].Children,
DateDiff('yyyy',[Date_of_birth],Now())+Int(Format(Now(),'mmdd')<Format([Date_of_birth],'mmdd')) AS [Dependant Age]
FROM [Dependants Details]
INNER JOIN [Staff Details] ON [Dependants Details].StaffID = [Staff Details].StaffID
WHERE DateDiff('yyyy',[Date_of_birth],Now())+Int(Format(Now(),'mmdd')<Format([Date_of_birth],'mmdd')) = True
GROUP BY [Dependants Details].DependantID, [Dependants Details].Name, [Dependants Details].Contact, [Dependants Details].Reationship, [Dependants Details].StaffID, [Dependants Details].Date_of_Birth, [Staff Details].Staff_Name, DateDiff('yyyy',[Date_of_birth],Now())+Int(Format(Now(),'mmdd')<Format([Date_of_birth],'mmdd')), [Dependants Details].Adults, [Dependants Details].Children

In your first post you didn't mention that you were joining. But either way, rather than confuse the database query any more than needed, I would recommend converting the data AFTER it has been retrieved and in the table write of the rows. That's if this is merely calculated for the sake of the print out?

For example, each row will have the data to be processed, so write a little script there...

if Age > 16 then 
    response.write"Adult"
else
    response.write"Child"
end if

Hi ArtistScope,

Thanks you for the reply, however, when I tried it there was no response, at all, the values did not change, when I tried this,

if dict("Age")  > 16 then
		
		dal.Dependants Details.Adults=Adult
		dal.Dependants Details.Add()
   else
   	dal.Dependants Details.Adults=Child
		dal.Dependants Details.Add()  
    end if

I got the error 424 Error description Object required in the process, any Idea???

These are the expected dictionary values... (dict, oldvalues,keys,inline) dict for new fields values, and oldvalues for values fields in the database.

Regards

In your first post you didn't mention that you were joining. But either way, rather than confuse the database query any more than needed, I would recommend converting the data AFTER it has been retrieved and in the table write of the rows. That's if this is merely calculated for the sake of the print out?

For example, each row will have the data to be processed, so write a little script there...

if Age > 16 then 
    response.write"Adult"
else
    response.write"Child"
end if

This is not what I suggested.

I have done that and what it does, it writes the value on the html at the top of the header, could there be any way it can be written to a field in the database, say for example, "Adult/Child" field??

Regards,

Erick

This is not what I suggested.

Ah! So now you want to write to a field in the database?

You need to do this from the form that writes the input to the database, and NOT from the output of the database rows.

Hi,

I appreciate much for your advice, however, to be honest, am not such an expert on ASP, I have quoted the asp handler where the details of the form are handled, here is where we have the DOB and the age fields values being processed, I have tried several options with the if statement but it seems not to work at all,

Regards

<!--#include file="include/dbcommon.asp"-->
<!--#include file="include/Dependants_Details_variables.asp"-->

<!--#include file="libs/xtempl.asp"-->
<%
dim xt
set xt = new XTempl
'	check if logged in
if SESSION("UserID")="" or not CheckSecurity(SESSION("_" & strTableName & "_OwnerID"),"Edit") then
	SESSION("MyURL")=request.ServerVariables("SCRIPT_NAME")&"?"&request.ServerVariables("QUERY_STRING")
	response.Redirect "login.asp?message=expired"
	response.End
end if

Set myRequest = CreateObject("Scripting.Dictionary")
Set myRequestFiles = CreateObject("Scripting.Dictionary")
if ParseMultiPartForm()=true then parse=1
MaxSizeSet=false

filename=""
status=""
message=""
usermessage=""
readevalues=false
errorhappened=false
bodyonload=""

set body=CreateObject("Scripting.Dictionary")

set showKeys = Server.CreateObject("Scripting.Dictionary")

inlineedit = false
templatefile = "Dependants_Details_edit.htm"

' connect database
dbConnection=""
db_connect()

DoEvent "BeforeProcessEdit dbConnection"

Set rs = server.CreateObject("ADODB.Recordset")
Set rsLookup = server.CreateObject("ADODB.Recordset")


set keys = CreateObject("Scripting.Dictionary")
keys("DependantID")=postvalue("editid1")

'	prepare data for saving
if getRequestForm("a")="edited" then


	sstrWhere=KeyWhere(keys,"")
	strSQL = "select * from " & AddTableWrappers(strOriginalTableName) & " where " & sstrWhere
	'	select only owned records
	if SecuritySQL("Edit")<>"" then
		strSQL = strSQL & " and " & SecuritySQL("Edit")
	end if
'	strSQL = AddWhere(strSQL,SecuritySQL("Edit"))
	set evalues = CreateObject("Scripting.Dictionary")
	set efilename_values = CreateObject("Scripting.Dictionary")
	set files_delete = CreateObject("Scripting.Dictionary")
	set files_move = CreateObject("Scripting.Dictionary")
	set files_save = CreateObject("Scripting.Dictionary")
	
	if not inlineedit then
'	processing Name - start
	value = postvalue("value_Name")
	ttype=postvalue("type_Name")
	toedit=true

if myRequest.Exists("value_Name") or myRequest.Exists("value_Name[]") or myRequest.Exists("type_Name") then
			value=prepare_for_db("Name",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Name") = value
			end if
	end if

	end if

'	processibng Name - end

	if not inlineedit then
'	processing Contact - start
	value = postvalue("value_Contact")
	ttype=postvalue("type_Contact")
	toedit=true

if myRequest.Exists("value_Contact") or myRequest.Exists("value_Contact[]") or myRequest.Exists("type_Contact") then
			value=prepare_for_db("Contact",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Contact") = value
			end if
	end if

	end if

'	processibng Contact - end

	if not inlineedit then
'	processing Reationship - start
	value = postvalue("value_Reationship")
	ttype=postvalue("type_Reationship")
	toedit=true

if myRequest.Exists("value_Reationship") or myRequest.Exists("value_Reationship[]") or myRequest.Exists("type_Reationship") then
			value=prepare_for_db("Reationship",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Reationship") = value
			end if
	end if

	end if

'	processibng Reationship - end

	if not inlineedit then
'	processing Date_of_Birth - start
	value = postvalue("value_Date_of_Birth")
	ttype=postvalue("type_Date_of_Birth")
	toedit=true

if myRequest.Exists("value_Date_of_Birth") or myRequest.Exists("value_Date_of_Birth[]") or myRequest.Exists("type_Date_of_Birth") then
			value=prepare_for_db("Date_of_Birth",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Date_of_Birth") = value
			end if
	end if

	end if

'	processibng Date_of_Birth - end

	if not inlineedit then
'	processing Staff_Name - start
	value = postvalue("value_Staff_Name")
	ttype=postvalue("type_Staff_Name")
	toedit=true

if myRequest.Exists("value_Staff_Name") or myRequest.Exists("value_Staff_Name[]") or myRequest.Exists("type_Staff_Name") then
			value=prepare_for_db("Staff_Name",value,ttype,"")
	value = false
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Staff_Name") = value
			end if
	end if

	end if

'	processibng Staff_Name - end

	if not inlineedit then
'	processing Age - start
	value = postvalue("value_Age")
	ttype=postvalue("type_Age")
	toedit=true

if myRequest.Exists("value_Age") or myRequest.Exists("value_Age[]") or myRequest.Exists("type_Age") then
			value=prepare_for_db("Age",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Age") = value
			end if
	end if

	end if

'	processibng Age - end

	if not inlineedit then
'	processing Adults - start
	value = postvalue("value_Adults")
	ttype=postvalue("type_Adults")
	toedit=true

if myRequest.Exists("value_Adults") or myRequest.Exists("value_Adults[]") or myRequest.Exists("type_Adults") then
			value=prepare_for_db("Adults",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Adults") = value
			end if
	end if

	end if

'	processibng Adults - end

	if not inlineedit then
'	processing Dependant Age - start
	value = postvalue("value_Dependant_Age")
	ttype=postvalue("type_Dependant_Age")
	toedit=true

if myRequest.Exists("value_Dependant_Age") or myRequest.Exists("value_Dependant_Age[]") or myRequest.Exists("type_Dependant_Age") then
			value=prepare_for_db("Dependant Age",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Dependant Age") = value
			end if
	end if

	end if

'	processibng Dependant Age - end


	for each ekey in efilename_values
		if evalues.Exists(ekey) then evalues.Remove(ekey)
		evalues(ekey) = efilename_values.Item(ekey)
	next
'	do event
	retval=true
	DoEvent "retval=BeforeEdit(evalues,sstrWhere,dataold,keys,usermessage,inlineedit)"
	if retval then
	on error resume next
	rs.Open strSQL, dbConnection, 1,2
	call report_error
	if IsUpdatable(rs("DependantID")) then
'	update DependantID field
	strValue=false
	if evalues.exists("DependantID") then 	_
		strValue = evalues.Item("DependantID")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_DependantID")
								if strValue<>"" and IsNumeric(strValue) then 
			rs("DependantID") = CLng(strValue)
		else
			rs("DependantID") = null
		end if
		call report_error
	end if
	end if
'	update Name field
	strValue=false
	if evalues.exists("Name") then 	_
		strValue = evalues.Item("Name")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Name")
								rs("Name") = strValue					
		call report_error
	end if
'	update Contact field
	strValue=false
	if evalues.exists("Contact") then 	_
		strValue = evalues.Item("Contact")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Contact")
								rs("Contact") = strValue					
		call report_error
	end if
'	update Reationship field
	strValue=false
	if evalues.exists("Reationship") then 	_
		strValue = evalues.Item("Reationship")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Reationship")
								rs("Reationship") = strValue					
		call report_error
	end if
'	update StaffID field
	strValue=false
	if evalues.exists("StaffID") then 	_
		strValue = evalues.Item("StaffID")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_StaffID")
								if strValue<>"" and IsNumeric(strValue) then 
			rs("StaffID") = CLng(strValue)
		else
			rs("StaffID") = null
		end if
		call report_error
	end if
'	update Date_of_Birth field
	strValue=false
	if evalues.exists("Date_of_Birth") then 	_
		strValue = evalues.Item("Date_of_Birth")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Date_of_Birth")
								if strValue="" then
			rs("Date_of_Birth")=null
		else
			rs("Date_of_Birth")=strValue
		end if
		call report_error
	end if
'	update Staff_Name field
	strValue=false
	if evalues.exists("Staff_Name") then 	_
		strValue = evalues.Item("Staff_Name")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Staff_Name")
								rs("Staff_Name") = strValue					
		call report_error
	end if
'	update Age field
	strValue=false
	if evalues.exists("Age") then 	_
		strValue = evalues.Item("Age")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Age")
								if strValue<>"" and IsNumeric(strValue) then 
			rs("Age") = CLng(strValue)
		else
			rs("Age") = null
		end if
		call report_error
	end if
'	update Adults field
	strValue=false
	if evalues.exists("Adults") then 	_
		strValue = evalues.Item("Adults")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Adults")
								rs("Adults") = strValue					
		call report_error
	end if
'	update Dependant Age field
	strValue=false
	if evalues.exists("Dependant Age") then 	_
		strValue = evalues.Item("Dependant Age")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Dependant_Age")
								if strValue<>"" and IsNumeric(strValue) then 
			rs("Dependant Age") = CLng(strValue)
		else
			rs("Dependant Age") = null
		end if
		call report_error
	end if
	if not errorhappened then
		rs.Update
		call report_error
	end if
	rs.Close
'	delete & move files
	on error goto 0
	if not errorhappened then
		Set fso = CreateObject("Scripting.FileSystemObject")
		for each file in files_delete 
			if fso.FileExists(file) then fso.DeleteFile(file)
		next
		for each file in files_move
			if fso.FileExists(file) then fso.MoveFile file(0),file(1)
		next
		for each file in files_save
		    WriteToFile Server.MapPath(file(0)), file(1)
		next
		Set fso=nothing
		if inlineedit then
			status="UPDATED"
			message="" & "Record updated" & ""
			IsSaved = true
		else
			message="<div class=message><<< " & "Record updated" & " >>></div>"
		end if
	if usermessage<>"" then _
		message=usermessage
	end if
	else
		readevalues=true
		message=usermessage
		status="DECLINED"
	end if
end if

'	get current values and show edit controls

strWhereClause=KeyWhere(keys,"")
'	select only owned records
strWhereClause = whereAdd(strWhereClause,SecuritySQL("Edit"))

strSQL = gSQLWhereAdd(strWhereClause)
strSQLbak = strSQL
DoEvent "BeforeQueryEdit strSQL,strWhereClause"
if strSQLbak = strSQL then
	strSQL = gSQLWhereAdd(strWhereClause)
end if
LogInfo(strSQL)
Set rs = nothing
Set rs = server.CreateObject("ADODB.Recordset")
rs.Open strSQL,dbConnection,1,2
if rs.EOF and not inlineedit then
	response.redirect "Dependants_Details_list.asp?a=return"
	response.end
end if

if not inlineedit then
    ' include files
    includes=""

    ' validation stuff
    onsubmit=""
        includes=includes & "<script language=""JavaScript"" src=""include/validate.js""></script>"
    includes=includes & "<script language=""JavaScript"">"
    includes=includes & "var TEXT_FIELDS_REQUIRED='" & addslashes("The Following fields are Required") & "';"
    includes=includes & "var TEXT_FIELDS_ZIPCODES='" & addslashes("") & "';"
    includes=includes & "var TEXT_FIELDS_EMAILS='" & addslashes("The Following fields must be valid Emails") & "';"
    includes=includes & "var TEXT_FIELDS_NUMBERS='" & addslashes("The Following fields must be Numbers") & "';"
    includes=includes & "var TEXT_FIELDS_CURRENCY='" & addslashes("The Following fields must be currency") & "';"
    includes=includes & "var TEXT_FIELDS_PHONE='" & addslashes("The Following fields must be Phone Numbers") & "';"
    includes=includes & "var TEXT_FIELDS_PASSWORD1='" & addslashes("The Following fields must be valid Passwords") & "';"
    includes=includes & "var TEXT_FIELDS_PASSWORD2='" & addslashes("should be at least 4 characters long") & "';"
    includes=includes & "var TEXT_FIELDS_PASSWORD3='" & addslashes("Cannot be 'password'") & "';"
    includes=includes & "var TEXT_FIELDS_STATE='" & addslashes("The Following fields must be State Names") & "';"
    includes=includes & "var TEXT_FIELDS_SSN='" & addslashes("The Following fields must be Social Security Numbers") & "';"
    includes=includes & "var TEXT_FIELDS_DATE='" & addslashes("The Following fields must be valid dates") & "';"
    includes=includes & "var TEXT_FIELDS_TIME='" & addslashes("The Following fields must be valid time in 24-hours format") & "';"
    includes=includes & "var TEXT_FIELDS_CC='" & addslashes("The Following fields must be valid Credit Card Numbers") & "';"
    includes=includes & "var TEXT_FIELDS_SSN='" & addslashes("The Following fields must be Social Security Numbers") & "';"
    includes=includes & "</script>"
          	    validatetype="IsNumeric"
    	    validatetype=validatetype & "IsRequired"
	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_DependantID','" & validatetype & "','Dependant ID');"
			bodyonload=bodyonload & "define('value_DependantID','" & validatetype & "','" & jsreplace("Dependant ID") & "');"
		end if
              	    validatetype=""
    	    validatetype=validatetype & "IsRequired"
	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_Name','" & validatetype & "','Dependant Name');"
			bodyonload=bodyonload & "define('value_Name','" & validatetype & "','" & jsreplace("Dependant Name") & "');"
		end if
              	    validatetype="IsNumeric"
    	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_StaffID','" & validatetype & "','Staff ID');"
			bodyonload=bodyonload & "define('value_StaffID','" & validatetype & "','" & jsreplace("Staff ID") & "');"
		end if
        	    validatetype=""
    	    validatetype=validatetype & "IsRequired"
	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_Date_of_Birth','" & validatetype & "','Date Of Birth');"
			bodyonload=bodyonload & "define('value_Date_of_Birth','" & validatetype & "','" & jsreplace("Date Of Birth") & "');"
		end if
              	    validatetype="IsNumeric"
    	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_Age','" & validatetype & "','Age');"
			bodyonload=bodyonload & "define('value_Age','" & validatetype & "','" & jsreplace("Age") & "');"
		end if
              	    validatetype="IsNumeric"
    	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_Dependant_Age','" & validatetype & "','Dependant Age');"
			bodyonload=bodyonload & "define('value_Dependant_Age','" & validatetype & "','" & jsreplace("Dependant Age") & "');"
		end if

    if bodyonload<>"" then onsubmit="return validate();"

    includes=includes & "<script language=""JavaScript"" src=""include/jquery.js""></script>"
    includes=includes & "<script language=""JavaScript"" src=""include/onthefly.js""></script>"

    if useAJAX then
	    includes=includes & "<script language=""JavaScript"" src=""include/ajaxsuggest.js""></script>"
    end if
    includes=includes & "<script language=""JavaScript"" src=""include/jsfunctions.js""></script>"
    includes=includes & "<script language=""JavaScript"">" & _
    "var locale_dateformat = " & locale_info("LOCALE_IDATE") & ";" & _
    "var locale_datedelimiter = """ & locale_info("LOCALE_SDATE") & """;" & _
    "var bLoading=false;" & _
    "var TEXT_PLEASE_SELECT='" & addslashes("Please select") & "';"
    if useAJAX then
	    includes=includes & "var SUGGEST_TABLE='Dependants_Details_searchsuggest.asp';" & vbcrlf
    end if
    includes=includes & "</script>" & vbcrlf
    if useAJAX then
	    includes=includes & "<div id=""search_suggest""></div>" & vbcrlf
    end if



    xt.assign "Name_fieldblock",true
    xt.assign "Contact_fieldblock",true
    xt.assign "Reationship_fieldblock",true
    xt.assign "Date_of_Birth_fieldblock",true
    xt.assign "Staff_Name_fieldblock",true
    xt.assign "Age_fieldblock",true
    xt.assign "Adults_fieldblock",true
    xt.assign "Dependant_Age_fieldblock",true

    if len(onsubmit)>0 then onsubmit="onSubmit=""" & onsubmit & """"
	body("begin")=includes & "<form name=""editform"" encType=""multipart/form-data"" method=""post"" action=""Dependants_Details_edit.asp"" " & onsubmit & "><input type=hidden name=""a"" value=""edited"">"
	body("begin")=body("begin") & "<input type=""hidden"" name=""editid1"" value=""" & my_htmlspecialchars(keys("DependantID")) & """>"
		xt.assign "show_key1", my_htmlspecialchars(GetData(rs,"DependantID", ""))

	xt.assign "backbutton_attrs","onclick=""window.location.href='Dependants_Details_list.asp?a=return'"""
	xt.assign "save_button",true
	xt.assign "reset_button",true
	xt.assign "back_button",true
end if



showKeys.Add "show_key1",SafeURLEncode(keys("DependantID"))

if message<>"" then
	xt.assign "message_block",true
	xt.assign "message",message
end if

set readonlyfields = CreateObject("Scripting.Dictionary")

' readonly fields
' readonly fields
' readonly fields
' readonly fields
' readonly fields
  	readonlyfields.Add "Staff_Name",GetData(rs,"Staff_Name", "HTML")
' readonly fields
' readonly fields
' readonly fields


linkdata=""

if useAJAX then
	record_id = postvalue("recordID")

	if inlineedit then
		linkdata = replace(linkdata,"&","&amp;")
		linkdata = replace(linkdata,"<","&lt;")
		linkdata = replace(linkdata,">","&gt;")
		xt.assign "linkdata",linkdata
	else 
		linkdata = "<script type=""text/javascript"">" & vbCrLf _
		 & "$(document).ready(function(){" & vbCrLf _
		 & linkdata & "});</script>"
	end if
else
    z=1
end if

body("end")="</form>" & linkdata & "<script>" & bodyonload & "</script><script>SetToFirstControl('editform');</script>"
xt.assign "body",body

where=sstrWhere


'/////////////////////////////////////////////////////////////
'//	prepare Edit Controls
'/////////////////////////////////////////////////////////////
set control_Name=CreateObject("Scripting.Dictionary")
control_Name("func")="xt_buildeditcontrol"
set control_Name("params") = CreateObject("Scripting.Dictionary")
control_Name("params")("field")="Name"
control_Name("params")("value")=rs("Name")

	if readevalues then
		control_Name("params")("value")=evalues("Name")
	else
		control_Name("params")("value")=dbvalue(rs("Name"))
	end if

' auto update fields

control_Name("params")("id")=record_id
if inlineedit then
	control_Name("params")("mode")="inline_edit"
else
	control_Name("params")("mode")="edit"
end if
	
xt.assign "Name_editcontrol",control_Name
set control_Contact=CreateObject("Scripting.Dictionary")
control_Contact("func")="xt_buildeditcontrol"
set control_Contact("params") = CreateObject("Scripting.Dictionary")
control_Contact("params")("field")="Contact"
control_Contact("params")("value")=rs("Contact")

	if readevalues then
		control_Contact("params")("value")=evalues("Contact")
	else
		control_Contact("params")("value")=dbvalue(rs("Contact"))
	end if

' auto update fields

control_Contact("params")("id")=record_id
if inlineedit then
	control_Contact("params")("mode")="inline_edit"
else
	control_Contact("params")("mode")="edit"
end if
	
xt.assign "Contact_editcontrol",control_Contact
set control_Reationship=CreateObject("Scripting.Dictionary")
control_Reationship("func")="xt_buildeditcontrol"
set control_Reationship("params") = CreateObject("Scripting.Dictionary")
control_Reationship("params")("field")="Reationship"
control_Reationship("params")("value")=rs("Reationship")

	if readevalues then
		control_Reationship("params")("value")=evalues("Reationship")
	else
		control_Reationship("params")("value")=dbvalue(rs("Reationship"))
	end if

' auto update fields

control_Reationship("params")("id")=record_id
if inlineedit then
	control_Reationship("params")("mode")="inline_edit"
else
	control_Reationship("params")("mode")="edit"
end if
	
xt.assign "Reationship_editcontrol",control_Reationship
set control_Date_of_Birth=CreateObject("Scripting.Dictionary")
control_Date_of_Birth("func")="xt_buildeditcontrol"
set control_Date_of_Birth("params") = CreateObject("Scripting.Dictionary")
control_Date_of_Birth("params")("field")="Date_of_Birth"
control_Date_of_Birth("params")("value")=rs("Date_of_Birth")

	if readevalues then
		control_Date_of_Birth("params")("value")=evalues("Date_of_Birth")
	else
		control_Date_of_Birth("params")("value")=dbvalue(rs("Date_of_Birth"))
	end if

' auto update fields

control_Date_of_Birth("params")("id")=record_id
if inlineedit then
	control_Date_of_Birth("params")("mode")="inline_edit"
else
	control_Date_of_Birth("params")("mode")="edit"
end if
	
xt.assign "Date_of_Birth_editcontrol",control_Date_of_Birth
set control_Staff_Name=CreateObject("Scripting.Dictionary")
control_Staff_Name("func")="xt_buildeditcontrol"
set control_Staff_Name("params") = CreateObject("Scripting.Dictionary")
control_Staff_Name("params")("field")="Staff_Name"
control_Staff_Name("params")("value")=rs("Staff_Name")

	if readevalues then
		control_Staff_Name("params")("value")=evalues("Staff_Name")
	else
		control_Staff_Name("params")("value")=dbvalue(rs("Staff_Name"))
	end if

' auto update fields

control_Staff_Name("params")("id")=record_id
if inlineedit then
	control_Staff_Name("params")("mode")="inline_edit"
else
	control_Staff_Name("params")("mode")="edit"
end if
	
xt.assign "Staff_Name_editcontrol",control_Staff_Name
set control_Age=CreateObject("Scripting.Dictionary")
control_Age("func")="xt_buildeditcontrol"
set control_Age("params") = CreateObject("Scripting.Dictionary")
control_Age("params")("field")="Age"
control_Age("params")("value")=rs("Age")

	if readevalues then
		control_Age("params")("value")=evalues("Age")
	else
		control_Age("params")("value")=dbvalue(rs("Age"))
	end if

' auto update fields

control_Age("params")("id")=record_id
if inlineedit then
	control_Age("params")("mode")="inline_edit"
else
	control_Age("params")("mode")="edit"
end if
	
xt.assign "Age_editcontrol",control_Age
set control_Adults=CreateObject("Scripting.Dictionary")
control_Adults("func")="xt_buildeditcontrol"
set control_Adults("params") = CreateObject("Scripting.Dictionary")
control_Adults("params")("field")="Adults"
control_Adults("params")("value")=rs("Adults")

	if readevalues then
		control_Adults("params")("value")=evalues("Adults")
	else
		control_Adults("params")("value")=dbvalue(rs("Adults"))
	end if

' auto update fields

control_Adults("params")("id")=record_id
if inlineedit then
	control_Adults("params")("mode")="inline_edit"
else
	control_Adults("params")("mode")="edit"
end if
	
xt.assign "Adults_editcontrol",control_Adults
set control_Dependant_Age=CreateObject("Scripting.Dictionary")
control_Dependant_Age("func")="xt_buildeditcontrol"
set control_Dependant_Age("params") = CreateObject("Scripting.Dictionary")
control_Dependant_Age("params")("field")="Dependant Age"
control_Dependant_Age("params")("value")=rs("Dependant Age")

	if readevalues then
		control_Dependant_Age("params")("value")=evalues("Dependant Age")
	else
		control_Dependant_Age("params")("value")=dbvalue(rs("Dependant Age"))
	end if

' auto update fields

control_Dependant_Age("params")("id")=record_id
if inlineedit then
	control_Dependant_Age("params")("mode")="inline_edit"
else
	control_Dependant_Age("params")("mode")="edit"
end if
	
xt.assign "Dependant_Age_editcontrol",control_Dependant_Age

'/////////////////////////////////////////////////////////////
'//display the page
'/////////////////////////////////////////////////////////////

DoEvent "BeforeShowEdit xt,templatefile"

xt.display(templatefile)

sub report_error
	if Err.number<>0 then
    	      message = "<div class=message><<< " & "Record was NOT edited" & " >>><br><br>" & Err.Description & "</div>"
    	  readevalues=true
	  errorhappened=true
	  err.clear
	end if
end sub
%>

Ah! So now you want to write to a field in the database?

You need to do this from the form that writes the input to the database, and NOT from the output of the database rows.

Hi,

I appreciate much for your advice, however, to be honest, am not such an expert on ASP, I have quoted the asp handler where the details of the form are handled, here is where we have the DOB and the age fields values being processed, I have tried several options with the if statement but it seems not to work at all,

Regards

<!--#include file="include/dbcommon.asp"-->
<!--#include file="include/Dependants_Details_variables.asp"-->

<!--#include file="libs/xtempl.asp"-->
<%
dim xt
set xt = new XTempl
'	check if logged in
if SESSION("UserID")="" or not CheckSecurity(SESSION("_" & strTableName & "_OwnerID"),"Edit") then
	SESSION("MyURL")=request.ServerVariables("SCRIPT_NAME")&"?"&request.ServerVariables("QUERY_STRING")
	response.Redirect "login.asp?message=expired"
	response.End
end if

Set myRequest = CreateObject("Scripting.Dictionary")
Set myRequestFiles = CreateObject("Scripting.Dictionary")
if ParseMultiPartForm()=true then parse=1
MaxSizeSet=false

filename=""
status=""
message=""
usermessage=""
readevalues=false
errorhappened=false
bodyonload=""

set body=CreateObject("Scripting.Dictionary")

set showKeys = Server.CreateObject("Scripting.Dictionary")

inlineedit = false
templatefile = "Dependants_Details_edit.htm"

' connect database
dbConnection=""
db_connect()

DoEvent "BeforeProcessEdit dbConnection"

Set rs = server.CreateObject("ADODB.Recordset")
Set rsLookup = server.CreateObject("ADODB.Recordset")


set keys = CreateObject("Scripting.Dictionary")
keys("DependantID")=postvalue("editid1")

'	prepare data for saving
if getRequestForm("a")="edited" then


	sstrWhere=KeyWhere(keys,"")
	strSQL = "select * from " & AddTableWrappers(strOriginalTableName) & " where " & sstrWhere
	'	select only owned records
	if SecuritySQL("Edit")<>"" then
		strSQL = strSQL & " and " & SecuritySQL("Edit")
	end if
'	strSQL = AddWhere(strSQL,SecuritySQL("Edit"))
	set evalues = CreateObject("Scripting.Dictionary")
	set efilename_values = CreateObject("Scripting.Dictionary")
	set files_delete = CreateObject("Scripting.Dictionary")
	set files_move = CreateObject("Scripting.Dictionary")
	set files_save = CreateObject("Scripting.Dictionary")
	
	if not inlineedit then
'	processing Name - start
	value = postvalue("value_Name")
	ttype=postvalue("type_Name")
	toedit=true

if myRequest.Exists("value_Name") or myRequest.Exists("value_Name[]") or myRequest.Exists("type_Name") then
			value=prepare_for_db("Name",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Name") = value
			end if
	end if

	end if

'	processibng Name - end

	if not inlineedit then
'	processing Contact - start
	value = postvalue("value_Contact")
	ttype=postvalue("type_Contact")
	toedit=true

if myRequest.Exists("value_Contact") or myRequest.Exists("value_Contact[]") or myRequest.Exists("type_Contact") then
			value=prepare_for_db("Contact",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Contact") = value
			end if
	end if

	end if

'	processibng Contact - end

	if not inlineedit then
'	processing Reationship - start
	value = postvalue("value_Reationship")
	ttype=postvalue("type_Reationship")
	toedit=true

if myRequest.Exists("value_Reationship") or myRequest.Exists("value_Reationship[]") or myRequest.Exists("type_Reationship") then
			value=prepare_for_db("Reationship",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Reationship") = value
			end if
	end if

	end if

'	processibng Reationship - end

	if not inlineedit then
'	processing Date_of_Birth - start
	value = postvalue("value_Date_of_Birth")
	ttype=postvalue("type_Date_of_Birth")
	toedit=true

if myRequest.Exists("value_Date_of_Birth") or myRequest.Exists("value_Date_of_Birth[]") or myRequest.Exists("type_Date_of_Birth") then
			value=prepare_for_db("Date_of_Birth",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Date_of_Birth") = value
			end if
	end if

	end if

'	processibng Date_of_Birth - end

	if not inlineedit then
'	processing Staff_Name - start
	value = postvalue("value_Staff_Name")
	ttype=postvalue("type_Staff_Name")
	toedit=true

if myRequest.Exists("value_Staff_Name") or myRequest.Exists("value_Staff_Name[]") or myRequest.Exists("type_Staff_Name") then
			value=prepare_for_db("Staff_Name",value,ttype,"")
	value = false
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Staff_Name") = value
			end if
	end if

	end if

'	processibng Staff_Name - end

	if not inlineedit then
'	processing Age - start
	value = postvalue("value_Age")
	ttype=postvalue("type_Age")
	toedit=true

if myRequest.Exists("value_Age") or myRequest.Exists("value_Age[]") or myRequest.Exists("type_Age") then
			value=prepare_for_db("Age",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Age") = value
			end if
	end if

	end if

'	processibng Age - end

	if not inlineedit then
'	processing Adults - start
	value = postvalue("value_Adults")
	ttype=postvalue("type_Adults")
	toedit=true

if myRequest.Exists("value_Adults") or myRequest.Exists("value_Adults[]") or myRequest.Exists("type_Adults") then
			value=prepare_for_db("Adults",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Adults") = value
			end if
	end if

	end if

'	processibng Adults - end

	if not inlineedit then
'	processing Dependant Age - start
	value = postvalue("value_Dependant_Age")
	ttype=postvalue("type_Dependant_Age")
	toedit=true

if myRequest.Exists("value_Dependant_Age") or myRequest.Exists("value_Dependant_Age[]") or myRequest.Exists("type_Dependant_Age") then
			value=prepare_for_db("Dependant Age",value,ttype,"")
	
		if vartype(value)=11 then 
			if value=false then _
				toedit=false
		end if
		if toedit then



			evalues("Dependant Age") = value
			end if
	end if

	end if

'	processibng Dependant Age - end


	for each ekey in efilename_values
		if evalues.Exists(ekey) then evalues.Remove(ekey)
		evalues(ekey) = efilename_values.Item(ekey)
	next
'	do event
	retval=true
	DoEvent "retval=BeforeEdit(evalues,sstrWhere,dataold,keys,usermessage,inlineedit)"
	if retval then
	on error resume next
	rs.Open strSQL, dbConnection, 1,2
	call report_error
	if IsUpdatable(rs("DependantID")) then
'	update DependantID field
	strValue=false
	if evalues.exists("DependantID") then 	_
		strValue = evalues.Item("DependantID")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_DependantID")
								if strValue<>"" and IsNumeric(strValue) then 
			rs("DependantID") = CLng(strValue)
		else
			rs("DependantID") = null
		end if
		call report_error
	end if
	end if
'	update Name field
	strValue=false
	if evalues.exists("Name") then 	_
		strValue = evalues.Item("Name")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Name")
								rs("Name") = strValue					
		call report_error
	end if
'	update Contact field
	strValue=false
	if evalues.exists("Contact") then 	_
		strValue = evalues.Item("Contact")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Contact")
								rs("Contact") = strValue					
		call report_error
	end if
'	update Reationship field
	strValue=false
	if evalues.exists("Reationship") then 	_
		strValue = evalues.Item("Reationship")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Reationship")
								rs("Reationship") = strValue					
		call report_error
	end if
'	update StaffID field
	strValue=false
	if evalues.exists("StaffID") then 	_
		strValue = evalues.Item("StaffID")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_StaffID")
								if strValue<>"" and IsNumeric(strValue) then 
			rs("StaffID") = CLng(strValue)
		else
			rs("StaffID") = null
		end if
		call report_error
	end if
'	update Date_of_Birth field
	strValue=false
	if evalues.exists("Date_of_Birth") then 	_
		strValue = evalues.Item("Date_of_Birth")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Date_of_Birth")
								if strValue="" then
			rs("Date_of_Birth")=null
		else
			rs("Date_of_Birth")=strValue
		end if
		call report_error
	end if
'	update Staff_Name field
	strValue=false
	if evalues.exists("Staff_Name") then 	_
		strValue = evalues.Item("Staff_Name")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Staff_Name")
								rs("Staff_Name") = strValue					
		call report_error
	end if
'	update Age field
	strValue=false
	if evalues.exists("Age") then 	_
		strValue = evalues.Item("Age")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Age")
								if strValue<>"" and IsNumeric(strValue) then 
			rs("Age") = CLng(strValue)
		else
			rs("Age") = null
		end if
		call report_error
	end if
'	update Adults field
	strValue=false
	if evalues.exists("Adults") then 	_
		strValue = evalues.Item("Adults")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Adults")
								rs("Adults") = strValue					
		call report_error
	end if
'	update Dependant Age field
	strValue=false
	if evalues.exists("Dependant Age") then 	_
		strValue = evalues.Item("Dependant Age")
		
	if not errorhappened and not (vartype(strValue)=11 and strValue=False) then
		if isnull(strValue) then strValue=""
		ctype = GetRequestForm("type_Dependant_Age")
								if strValue<>"" and IsNumeric(strValue) then 
			rs("Dependant Age") = CLng(strValue)
		else
			rs("Dependant Age") = null
		end if
		call report_error
	end if
	if not errorhappened then
		rs.Update
		call report_error
	end if
	rs.Close
'	delete & move files
	on error goto 0
	if not errorhappened then
		Set fso = CreateObject("Scripting.FileSystemObject")
		for each file in files_delete 
			if fso.FileExists(file) then fso.DeleteFile(file)
		next
		for each file in files_move
			if fso.FileExists(file) then fso.MoveFile file(0),file(1)
		next
		for each file in files_save
		    WriteToFile Server.MapPath(file(0)), file(1)
		next
		Set fso=nothing
		if inlineedit then
			status="UPDATED"
			message="" & "Record updated" & ""
			IsSaved = true
		else
			message="<div class=message><<< " & "Record updated" & " >>></div>"
		end if
	if usermessage<>"" then _
		message=usermessage
	end if
	else
		readevalues=true
		message=usermessage
		status="DECLINED"
	end if
end if

'	get current values and show edit controls

strWhereClause=KeyWhere(keys,"")
'	select only owned records
strWhereClause = whereAdd(strWhereClause,SecuritySQL("Edit"))

strSQL = gSQLWhereAdd(strWhereClause)
strSQLbak = strSQL
DoEvent "BeforeQueryEdit strSQL,strWhereClause"
if strSQLbak = strSQL then
	strSQL = gSQLWhereAdd(strWhereClause)
end if
LogInfo(strSQL)
Set rs = nothing
Set rs = server.CreateObject("ADODB.Recordset")
rs.Open strSQL,dbConnection,1,2
if rs.EOF and not inlineedit then
	response.redirect "Dependants_Details_list.asp?a=return"
	response.end
end if

if not inlineedit then
    ' include files
    includes=""

    ' validation stuff
    onsubmit=""
        includes=includes & "<script language=""JavaScript"" src=""include/validate.js""></script>"
    includes=includes & "<script language=""JavaScript"">"
    includes=includes & "var TEXT_FIELDS_REQUIRED='" & addslashes("The Following fields are Required") & "';"
    includes=includes & "var TEXT_FIELDS_ZIPCODES='" & addslashes("") & "';"
    includes=includes & "var TEXT_FIELDS_EMAILS='" & addslashes("The Following fields must be valid Emails") & "';"
    includes=includes & "var TEXT_FIELDS_NUMBERS='" & addslashes("The Following fields must be Numbers") & "';"
    includes=includes & "var TEXT_FIELDS_CURRENCY='" & addslashes("The Following fields must be currency") & "';"
    includes=includes & "var TEXT_FIELDS_PHONE='" & addslashes("The Following fields must be Phone Numbers") & "';"
    includes=includes & "var TEXT_FIELDS_PASSWORD1='" & addslashes("The Following fields must be valid Passwords") & "';"
    includes=includes & "var TEXT_FIELDS_PASSWORD2='" & addslashes("should be at least 4 characters long") & "';"
    includes=includes & "var TEXT_FIELDS_PASSWORD3='" & addslashes("Cannot be 'password'") & "';"
    includes=includes & "var TEXT_FIELDS_STATE='" & addslashes("The Following fields must be State Names") & "';"
    includes=includes & "var TEXT_FIELDS_SSN='" & addslashes("The Following fields must be Social Security Numbers") & "';"
    includes=includes & "var TEXT_FIELDS_DATE='" & addslashes("The Following fields must be valid dates") & "';"
    includes=includes & "var TEXT_FIELDS_TIME='" & addslashes("The Following fields must be valid time in 24-hours format") & "';"
    includes=includes & "var TEXT_FIELDS_CC='" & addslashes("The Following fields must be valid Credit Card Numbers") & "';"
    includes=includes & "var TEXT_FIELDS_SSN='" & addslashes("The Following fields must be Social Security Numbers") & "';"
    includes=includes & "</script>"
          	    validatetype="IsNumeric"
    	    validatetype=validatetype & "IsRequired"
	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_DependantID','" & validatetype & "','Dependant ID');"
			bodyonload=bodyonload & "define('value_DependantID','" & validatetype & "','" & jsreplace("Dependant ID") & "');"
		end if
              	    validatetype=""
    	    validatetype=validatetype & "IsRequired"
	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_Name','" & validatetype & "','Dependant Name');"
			bodyonload=bodyonload & "define('value_Name','" & validatetype & "','" & jsreplace("Dependant Name") & "');"
		end if
              	    validatetype="IsNumeric"
    	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_StaffID','" & validatetype & "','Staff ID');"
			bodyonload=bodyonload & "define('value_StaffID','" & validatetype & "','" & jsreplace("Staff ID") & "');"
		end if
        	    validatetype=""
    	    validatetype=validatetype & "IsRequired"
	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_Date_of_Birth','" & validatetype & "','Date Of Birth');"
			bodyonload=bodyonload & "define('value_Date_of_Birth','" & validatetype & "','" & jsreplace("Date Of Birth") & "');"
		end if
              	    validatetype="IsNumeric"
    	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_Age','" & validatetype & "','Age');"
			bodyonload=bodyonload & "define('value_Age','" & validatetype & "','" & jsreplace("Age") & "');"
		end if
              	    validatetype="IsNumeric"
    	    if validatetype<>"" then 
'			bodyonload=bodyonload & "define('value_Dependant_Age','" & validatetype & "','Dependant Age');"
			bodyonload=bodyonload & "define('value_Dependant_Age','" & validatetype & "','" & jsreplace("Dependant Age") & "');"
		end if

    if bodyonload<>"" then onsubmit="return validate();"

    includes=includes & "<script language=""JavaScript"" src=""include/jquery.js""></script>"
    includes=includes & "<script language=""JavaScript"" src=""include/onthefly.js""></script>"

    if useAJAX then
	    includes=includes & "<script language=""JavaScript"" src=""include/ajaxsuggest.js""></script>"
    end if
    includes=includes & "<script language=""JavaScript"" src=""include/jsfunctions.js""></script>"
    includes=includes & "<script language=""JavaScript"">" & _
    "var locale_dateformat = " & locale_info("LOCALE_IDATE") & ";" & _
    "var locale_datedelimiter = """ & locale_info("LOCALE_SDATE") & """;" & _
    "var bLoading=false;" & _
    "var TEXT_PLEASE_SELECT='" & addslashes("Please select") & "';"
    if useAJAX then
	    includes=includes & "var SUGGEST_TABLE='Dependants_Details_searchsuggest.asp';" & vbcrlf
    end if
    includes=includes & "</script>" & vbcrlf
    if useAJAX then
	    includes=includes & "<div id=""search_suggest""></div>" & vbcrlf
    end if



    xt.assign "Name_fieldblock",true
    xt.assign "Contact_fieldblock",true
    xt.assign "Reationship_fieldblock",true
    xt.assign "Date_of_Birth_fieldblock",true
    xt.assign "Staff_Name_fieldblock",true
    xt.assign "Age_fieldblock",true
    xt.assign "Adults_fieldblock",true
    xt.assign "Dependant_Age_fieldblock",true

    if len(onsubmit)>0 then onsubmit="onSubmit=""" & onsubmit & """"
	body("begin")=includes & "<form name=""editform"" encType=""multipart/form-data"" method=""post"" action=""Dependants_Details_edit.asp"" " & onsubmit & "><input type=hidden name=""a"" value=""edited"">"
	body("begin")=body("begin") & "<input type=""hidden"" name=""editid1"" value=""" & my_htmlspecialchars(keys("DependantID")) & """>"
		xt.assign "show_key1", my_htmlspecialchars(GetData(rs,"DependantID", ""))

	xt.assign "backbutton_attrs","onclick=""window.location.href='Dependants_Details_list.asp?a=return'"""
	xt.assign "save_button",true
	xt.assign "reset_button",true
	xt.assign "back_button",true
end if



showKeys.Add "show_key1",SafeURLEncode(keys("DependantID"))

if message<>"" then
	xt.assign "message_block",true
	xt.assign "message",message
end if

set readonlyfields = CreateObject("Scripting.Dictionary")

' readonly fields
' readonly fields
' readonly fields
' readonly fields
' readonly fields
  	readonlyfields.Add "Staff_Name",GetData(rs,"Staff_Name", "HTML")
' readonly fields
' readonly fields
' readonly fields


linkdata=""

if useAJAX then
	record_id = postvalue("recordID")

	if inlineedit then
		linkdata = replace(linkdata,"&","&amp;")
		linkdata = replace(linkdata,"<","&lt;")
		linkdata = replace(linkdata,">","&gt;")
		xt.assign "linkdata",linkdata
	else 
		linkdata = "<script type=""text/javascript"">" & vbCrLf _
		 & "$(document).ready(function(){" & vbCrLf _
		 & linkdata & "});</script>"
	end if
else
    z=1
end if

body("end")="</form>" & linkdata & "<script>" & bodyonload & "</script><script>SetToFirstControl('editform');</script>"
xt.assign "body",body

where=sstrWhere


'/////////////////////////////////////////////////////////////
'//	prepare Edit Controls
'/////////////////////////////////////////////////////////////
set control_Name=CreateObject("Scripting.Dictionary")
control_Name("func")="xt_buildeditcontrol"
set control_Name("params") = CreateObject("Scripting.Dictionary")
control_Name("params")("field")="Name"
control_Name("params")("value")=rs("Name")

	if readevalues then
		control_Name("params")("value")=evalues("Name")
	else
		control_Name("params")("value")=dbvalue(rs("Name"))
	end if

' auto update fields

control_Name("params")("id")=record_id
if inlineedit then
	control_Name("params")("mode")="inline_edit"
else
	control_Name("params")("mode")="edit"
end if
	
xt.assign "Name_editcontrol",control_Name
set control_Contact=CreateObject("Scripting.Dictionary")
control_Contact("func")="xt_buildeditcontrol"
set control_Contact("params") = CreateObject("Scripting.Dictionary")
control_Contact("params")("field")="Contact"
control_Contact("params")("value")=rs("Contact")

	if readevalues then
		control_Contact("params")("value")=evalues("Contact")
	else
		control_Contact("params")("value")=dbvalue(rs("Contact"))
	end if

' auto update fields

control_Contact("params")("id")=record_id
if inlineedit then
	control_Contact("params")("mode")="inline_edit"
else
	control_Contact("params")("mode")="edit"
end if
	
xt.assign "Contact_editcontrol",control_Contact
set control_Reationship=CreateObject("Scripting.Dictionary")
control_Reationship("func")="xt_buildeditcontrol"
set control_Reationship("params") = CreateObject("Scripting.Dictionary")
control_Reationship("params")("field")="Reationship"
control_Reationship("params")("value")=rs("Reationship")

	if readevalues then
		control_Reationship("params")("value")=evalues("Reationship")
	else
		control_Reationship("params")("value")=dbvalue(rs("Reationship"))
	end if

' auto update fields

control_Reationship("params")("id")=record_id
if inlineedit then
	control_Reationship("params")("mode")="inline_edit"
else
	control_Reationship("params")("mode")="edit"
end if
	
xt.assign "Reationship_editcontrol",control_Reationship
set control_Date_of_Birth=CreateObject("Scripting.Dictionary")
control_Date_of_Birth("func")="xt_buildeditcontrol"
set control_Date_of_Birth("params") = CreateObject("Scripting.Dictionary")
control_Date_of_Birth("params")("field")="Date_of_Birth"
control_Date_of_Birth("params")("value")=rs("Date_of_Birth")

	if readevalues then
		control_Date_of_Birth("params")("value")=evalues("Date_of_Birth")
	else
		control_Date_of_Birth("params")("value")=dbvalue(rs("Date_of_Birth"))
	end if

' auto update fields

control_Date_of_Birth("params")("id")=record_id
if inlineedit then
	control_Date_of_Birth("params")("mode")="inline_edit"
else
	control_Date_of_Birth("params")("mode")="edit"
end if
	
xt.assign "Date_of_Birth_editcontrol",control_Date_of_Birth
set control_Staff_Name=CreateObject("Scripting.Dictionary")
control_Staff_Name("func")="xt_buildeditcontrol"
set control_Staff_Name("params") = CreateObject("Scripting.Dictionary")
control_Staff_Name("params")("field")="Staff_Name"
control_Staff_Name("params")("value")=rs("Staff_Name")

	if readevalues then
		control_Staff_Name("params")("value")=evalues("Staff_Name")
	else
		control_Staff_Name("params")("value")=dbvalue(rs("Staff_Name"))
	end if

' auto update fields

control_Staff_Name("params")("id")=record_id
if inlineedit then
	control_Staff_Name("params")("mode")="inline_edit"
else
	control_Staff_Name("params")("mode")="edit"
end if
	
xt.assign "Staff_Name_editcontrol",control_Staff_Name
set control_Age=CreateObject("Scripting.Dictionary")
control_Age("func")="xt_buildeditcontrol"
set control_Age("params") = CreateObject("Scripting.Dictionary")
control_Age("params")("field")="Age"
control_Age("params")("value")=rs("Age")

	if readevalues then
		control_Age("params")("value")=evalues("Age")
	else
		control_Age("params")("value")=dbvalue(rs("Age"))
	end if

' auto update fields

control_Age("params")("id")=record_id
if inlineedit then
	control_Age("params")("mode")="inline_edit"
else
	control_Age("params")("mode")="edit"
end if
	
xt.assign "Age_editcontrol",control_Age
set control_Adults=CreateObject("Scripting.Dictionary")
control_Adults("func")="xt_buildeditcontrol"
set control_Adults("params") = CreateObject("Scripting.Dictionary")
control_Adults("params")("field")="Adults"
control_Adults("params")("value")=rs("Adults")

	if readevalues then
		control_Adults("params")("value")=evalues("Adults")
	else
		control_Adults("params")("value")=dbvalue(rs("Adults"))
	end if

' auto update fields

control_Adults("params")("id")=record_id
if inlineedit then
	control_Adults("params")("mode")="inline_edit"
else
	control_Adults("params")("mode")="edit"
end if
	
xt.assign "Adults_editcontrol",control_Adults
set control_Dependant_Age=CreateObject("Scripting.Dictionary")
control_Dependant_Age("func")="xt_buildeditcontrol"
set control_Dependant_Age("params") = CreateObject("Scripting.Dictionary")
control_Dependant_Age("params")("field")="Dependant Age"
control_Dependant_Age("params")("value")=rs("Dependant Age")

	if readevalues then
		control_Dependant_Age("params")("value")=evalues("Dependant Age")
	else
		control_Dependant_Age("params")("value")=dbvalue(rs("Dependant Age"))
	end if

' auto update fields

control_Dependant_Age("params")("id")=record_id
if inlineedit then
	control_Dependant_Age("params")("mode")="inline_edit"
else
	control_Dependant_Age("params")("mode")="edit"
end if
	
xt.assign "Dependant_Age_editcontrol",control_Dependant_Age

'/////////////////////////////////////////////////////////////
'//display the page
'/////////////////////////////////////////////////////////////

DoEvent "BeforeShowEdit xt,templatefile"

xt.display(templatefile)

sub report_error
	if Err.number<>0 then
    	      message = "<div class=message><<< " & "Record was NOT edited" & " >>><br><br>" & Err.Description & "</div>"
    	  readevalues=true
	  errorhappened=true
	  err.clear
	end if
end sub
%>

And this is the Dbcommon file being recalled

<%@codepage=1252%>
<%

cCharset = "Windows-1252"

response.Charset=cCharset

dDebug=false
useAJAX=true
suggestAllContent=true

Session.LCID = 1033
session.codepage=1252

dSQL=""
bSubqueriesSupported=true

strDatabaseType = "ACCESS"

Set tables_data = CreateObject("Scripting.Dictionary")
Set field_labels = CreateObject("Scripting.Dictionary")

%>
<!--#include file="locale.asp"-->
<!--#include file="events.asp"-->
<!--#include file="commonfunctions.asp"-->
<!--#include file="dbconnection.asp"-->
<!--#include file="dal_source.asp"-->

<%
Const FORMAT_NONE					= ""
Const FORMAT_DATE_SHORT				= "Short Date"
Const FORMAT_DATE_LONG				= "Long Date"
Const FORMAT_DATE_TIME				= "Datetime"
Const FORMAT_TIME					= "Time"
Const FORMAT_CURRENCY				= "Currency"
Const FORMAT_PERCENT				= "Percent"
Const FORMAT_HYPERLINK				= "Hyperlink"
Const FORMAT_EMAILHYPERLINK			= "Email Hyperlink"
Const FORMAT_FILE_IMAGE				= "File-based Image"
Const FORMAT_DATABASE_IMAGE			= "Database Image"
Const FORMAT_DATABASE_FILE			= "Database File"
Const FORMAT_FILE					= "Document Download"
Const FORMAT_LOOKUP_WIZARD			= "Lookup wizard"
Const FORMAT_PHONE_NUMBER			= "Phone Number"
Const FORMAT_NUMBER					= "Number"
Const FORMAT_HTML					= "HTML"
Const FORMAT_CHECKBOX				= "Checkbox"
Const FORMAT_CUSTOM					= "Custom"

Const EDIT_FORMAT_NONE				= ""
Const EDIT_FORMAT_TEXT_FIELD		= "Text field"
Const EDIT_FORMAT_TEXT_AREA			= "Text area"
Const EDIT_FORMAT_PASSWORD			= "Password"
Const EDIT_FORMAT_DATE				= "Date"
Const EDIT_FORMAT_TIME				= "Time"
Const EDIT_FORMAT_RADIO				= "Radio button"
Const EDIT_FORMAT_CHECKBOX			= "Checkbox"
Const EDIT_FORMAT_DATABASE_IMAGE	= "Database image"
Const EDIT_FORMAT_DATABASE_FILE		= "Database file"
Const EDIT_FORMAT_FILE				= "Document upload"
Const EDIT_FORMAT_LOOKUP_WIZARD		= "Lookup wizard"
Const EDIT_FORMAT_HIDDEN			= "Hidden field"
Const EDIT_FORMAT_READONLY			= "Readonly"

Const EDIT_DATE_SIMPLE				= 0
Const EDIT_DATE_SIMPLE_DP			= 11
Const EDIT_DATE_DD					= 12
Const EDIT_DATE_DD_DP				= 13

Const MODE_ADD						= 0
Const MODE_EDIT						= 1
Const MODE_SEARCH					= 2
Const MODE_LIST						= 3
Const MODE_PRINT					= 4
Const MODE_VIEW						= 5
Const MODE_INLINE_ADD				= 6
Const MODE_INLINE_EDIT				= 7

Const LOGIN_HARDCODED				= 0
Const LOGIN_TABLE					= 1

Const ADVSECURITY_ALL				= 0
Const ADVSECURITY_VIEW_OWN			= 1
Const ADVSECURITY_EDIT_OWN			= 2
Const ADVSECURITY_NONE				= 3

Const ACCESS_LEVEL_ADMIN			= "Admin"
Const ACCESS_LEVEL_ADMINGROUP		= "AdminGroup"
Const ACCESS_LEVEL_USER				= "User"
Const ACCESS_LEVEL_GUEST			= "Guest"

Const DATABASE_MySQL				= "MYSQL"
Const DATABASE_Oracle				= "ORACLE"
Const DATABASE_MSSQLServer			= "MS SQL SERVER"
Const DATABASE_Access				= "ACCESS"

Const RTE_BASIC 				= "BASIC"
Const RTE_FCK 					= "FCK"
Const RTE_INNOVA				= "INNOVA"

Const ADD_SIMPLE  				= 0
Const ADD_INLINE 				= 1
Const ADD_ONTHEFLY 				= 2

Const LIST_SIMPLE               = 0
Const LIST_LOOKUP               = 1

Const LCT_DROPDOWN              = 0
Const LCT_AJAX                  = 1
Const LCT_LIST                  = 2

Const LT_LISTOFVALUES 	= 0
Const LT_LOOKUPTABLE 	= 1



strLeftWrapper="["
strRightWrapper="]"

cLoginTable				= ""
cUserNameField			= "username"
cPasswordField			= "password"
cUserGroupField			= "username"
cEmailField				= "Email ()"

cFrom 					= ""
cSmtpServer 			= ""
cSmtpPort 				= ""
cSMTPUser				= ""
cSMTPPassword			= ""


	gPermissionsRefreshTime=0
	gPermissionsRead=false

function db_connect()
	set dbConnection = server.CreateObject("ADODB.Connection")
   	dbConnection.ConnectionString = strConnection
   	dbConnection.Open
end function
function AddTableWrappers(strName)
	if mid(strName,1,1)=strLeftWrapper then
		AddTableWrappers = strName
		exit function
	end if
	dim arr
	arr=split(strName,".")
	ret=strLeftWrapper & arr(0) & strRightWrapper
	if ubound(arr)>0 then ret=ret & "." & strLeftWrapper & arr(1) & strRightWrapper
	AddTableWrappers = ret
end function

function db_upper(dbval)
	db_upper = "ucase(" & dbval & ")"
end function

function AddFieldWrappers(strName)
	if mid(strName,1,1)=strLeftWrapper then
		AddFieldWrappers = strName
	else
		AddFieldWrappers = strLeftWrapper & strName & strRightWrapper
	end if
end function
function FieldNeedQuotes(rs,field)
	ttype=db_fieldtype(rs,field)
	if ttype=20 or ttype=128 or ttype=11 or ttype=6 or ttype=14 or ttype=5 or ttype=3 or ttype=131 _
	or ttype=4	or ttype=2	or ttype=16 or ttype=21 or ttype=19 or ttype=18 or ttype=17 or ttype=139 then
		FieldNeedQuotes = false
	else
		FieldNeedQuotes = true
	end if
end function
function db_addslashes(str)
	db_addslashes = replace(str,"'","''")
end function
function db_datequotes(val)
	db_datequotes = "#" & val & "#"
end function
function db_stripslashesbinary(str)
'//	try to remove ole header for BMP pictures
	pos = instrb(str,unicode2bytes(".Picture"))
	if pos=0 or pos>300 then 
		db_stripslashesbinary = str
		exit function
	end if
	pos1=instrb(pos,str,unicode2bytes("BM"))
	if pos1=0 or pos1>300 then
		db_stripslashesbinary = str
		exit function
	end if
	db_stripslashesbinary = midb(str,pos1)
end function

function db_fieldtype(lhandle,fname)
	Dim i
	for i=0 to db_numfields(lhandle)-1
		if db_fieldname(lhandle,i)=fname then
			ttype=db_fieldtypen(lhandle,i)
			db_fieldtype = ttype
			exit function
		end if
	next
	db_fieldtype = ""
end function
function db_numfields(lhandle)
	db_numfields = lhandle.Fields.Count
end function

function db_fieldname(lhandle,fnumber)
	db_fieldname = lhandle.Fields(fnumber).Name
end function

function db_fieldtypen(lhandle,fnumber)
	db_fieldtypen = lhandle.Fields(fnumber).Type
end function

function date2str(val)
	if isnull(val) then
		date2str=""
		exit function
	end if
	if isdate(val) then
		date2str = CStr(year(val)) & "-" & CStr(month(val)) & "-" & CStr(day(val)) & _
				" " & CStr(hour(val)) & ":" & CStr(minute(val)) & ":" & CStr(second(val))
		exit function
	end if
	date2str=""
end function

Function CalcSearchParameters

	dim ret
	ret=""
	if SESSION(strTableName & "_search")=2 then
	'	 advanced search
		
		set strTableName_asearchfortype = SESSION(strTableName & "_asearchfortype")
		set strTableName_asearchnot = SESSION(strTableName & "_asearchnot")
		set strTableName_asearchopt = SESSION(strTableName & "_asearchopt")
		set strTableName_asearchfor = SESSION(strTableName & "_asearchfor")
		set strTableName_asearchfor2 = SESSION(strTableName & "_asearchfor2")

		sWhere=""
		for each f in strTableName_asearchfor
			strSearchFor=trim(strTableName_asearchfor.item(f))
			strSearchFor2=""
			ttype=strTableName_asearchfortype.item(f)
			
			for each i in strTableName_asearchfor2
				if f=i then strSearchFor2=trim(strTableName_asearchfor2.item(i))
			next
		
			if strSearchFor<>"" or true then
				if sWhere="" then
					if session(strTableName & "_asearchtype")="and" then
						sWhere="1=1"
					else
						sWhere="1=0"
					end if
				end if
				snot=strTableName_asearchnot.item(f)
				strSearchOption=trim(strTableName_asearchopt.Item(f))
				where=""
				where=StrWhereAdv(f, strSearchFor, strSearchOption, strSearchFor2,ttype)
				if where<>"" then
					if snot<>"" then where="not (" & where & ")"
					if SESSION(strTableName & "_asearchtype")="and" then
	   					sWhere=sWhere &  " and " & where
					else
	   					sWhere=sWhere &  " or " & where
	   				end if
				end if
			end if
		next
		ret=whereAdd(ret,sWhere)
	end if
	CalcSearchParameters = ret
End Function

%>

Wow! 1,100+ lines of code to do what you want that could be done in 20-30 lines... if only you understand simple ASP.

I know, LOL, but the problem is I don't know much, I use Code generators, and can only do simple modifications after that... I have done plenty, but this one is proving to be hell.... I use ASPRunner 6.0....

That is why I pointed earlier that I am not good enough in this...

Wow! 1,100+ lines of code to do what you want that could be done in 20-30 lines... if only you understand simple ASP.

ASPRunner is cool for creating backend admin pages for an existing database/solution, and for quickly creating some solutions, but it's not very customize-me friendly.

So you have existing data created by your existing solution, and you want to simply print out or you want to change the data before it's input to the database. I think that ASPRunner already provides the option of manipulating input data.

Simple question... when data is entered you want the scripts to automatically change the data or input an extra field for Adult/Child? So that it is stored as Adult/Child?

If so why? How and when would this criteria be used? For example when sorting the results by Adult/Child? Because sorting can be done in your results table as I described earlier.

The reason why I need adult/child field is because I have already calculated the ages from the DOB and in reports, I wanted to have the number of total adults and number of total Children grouped by count... This brings values of 1 all through if the grouping is done by Count of "age". So that is why apart from having the age values for referencing, I wanted the Field Adult/child to display the respective value... Where am stuck is how to insert the Adult in case age is greater than 16 and Child in case Age is greater than or equal to 16... These should be on the database field and not on the HTML, for the SQL queries to work on the report...

Any help would highly be appreciated...

ASPRunner is cool for creating backend admin pages for an existing database/solution, and for quickly creating some solutions, but it's not very customize-me friendly.

So you have existing data created by your existing solution, and you want to simply print out or you want to change the data before it's input to the database. I think that ASPRunner already provides the option of manipulating input data.

Simple question... when data is entered you want the scripts to automatically change the data or input an extra field for Adult/Child? So that it is stored as Adult/Child?

If so why? How and when would this criteria be used? For example when sorting the results by Adult/Child? Because sorting can be done in your results table as I described earlier.

So add a new field to the database and set its value as a stored procedure/value...

If other field is greater than 16 then new field = 1

If so why? How and when would this criteria be used? For example when sorting the results by Adult/Child? Because sorting can be done in your results table as I described earlier.

Okay here is what I wanted to do, when a user inserts details in there Date of Birth field, age is calculated in the "Age" field. After the age has been calculated, then depending on the condition earlier mentioned, the Adult/Child is populated automaticaly with the respective details for the user, eg, Adult if the Age is >16 or Child if the Age is <= 16...

ASPRunner is cool for creating backend admin pages for an existing database/solution, and for quickly creating some solutions, but it's not very customize-me friendly.

So you have existing data created by your existing solution, and you want to simply print out or you want to change the data before it's input to the database. I think that ASPRunner already provides the option of manipulating input data.

Simple question... when data is entered you want the scripts to automatically change the data or input an extra field for Adult/Child? So that it is stored as Adult/Child?

If so why? How and when would this criteria be used? For example when sorting the results by Adult/Child? Because sorting can be done in your results table as I described earlier.

I will try this and see what it does... I use access for development and will late transfere it to msSQL later... Thanks anyway... Am still ready for any advice you would give...

Regards

So add a new field to the database and set its value as a stored procedure/value...

If other field is greater than 16 then new field = 1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.