<% ' Initialize common variables x_contactid = Null: ox_contactid = Null: z_contactid = Null x_Name = Null: ox_Name = Null: z_Name = Null x_Email = Null: ox_Email = Null: z_Email = Null x_mobile = Null: ox_mobile = Null: z_mobile = Null x_origin = Null: ox_origin = Null: z_origin = Null x_destination = Null: ox_destination = Null: z_destination = Null x_departure = Null: ox_departure = Null: z_departure = Null x_dateArrival = Null: ox_dateArrival = Null: z_dateArrival = Null x_Reference = Null: ox_Reference = Null: z_Reference = Null x_personstraveling = Null: ox_personstraveling = Null: z_personstraveling = Null x_trip_requirement = Null: ox_trip_requirement = Null: z_trip_requirement = Null %> <% Response.Buffer = True ' Load key from QueryString bCopy = True x_contactid = Request.QueryString("contactid") If x_contactid = "" Or IsNull(x_contactid) Then bCopy = False End If ' Get action sAction = Request.Form("a_add") If (sAction = "" Or IsNull(sAction)) Then If bCopy Then sAction = "C" ' Copy record Else sAction = "I" ' Display blank record End If Else ' Get fields from form x_contactid = Request.Form("x_contactid") x_Name = Request.Form("x_Name") x_Email = Request.Form("x_Email") x_mobile = Request.Form("x_mobile") x_origin = Request.Form("x_origin") x_destination = Request.Form("x_destination") x_departure = Request.Form("x_departure") x_dateArrival = Request.Form("x_dateArrival") x_Reference = Request.Form("x_Reference") x_personstraveling = Request.Form("x_personstraveling") x_trip_requirement = Request.Form("x_trip_requirement") End If ' Open connection to the database Set conn = Server.CreateObject("ADODB.Connection") conn.Open xDb_Conn_Str Select Case sAction Case "C": ' Get a record to display If Not LoadData() Then ' Load Record based on key Session(ewSessionMessage) = "No records found" conn.Close ' Close Connection Set conn = Nothing Response.Clear Response.Redirect "contact.asp" End If Case "A": ' Add If AddData() Then ' Add New Record Session(ewSessionMessage) = "Add New Record Successful" conn.Close ' Close Connection Set conn = Nothing Response.Clear Response.Redirect "contactdone.asp" Else End If End Select %>

Name ">
Email * ">
Mobile * ">
Place of Origin ">
Place of Destination ">
Date Of Departure ">  Pick a Date
Date of Arrival ">  Pick a Date
Reference <% lst_x_Reference = "" Response.Write lst_x_Reference %>
No. Of Persons Traveling ">
Trip Requirements

<% conn.Close ' Close Connection Set conn = Nothing %> <% '------------------------------------------------------------------------------- ' Function LoadData ' - Load Data based on Key Value ' - Variables setup: field variables Function LoadData() Dim rs, sSql, sFilter sFilter = ewSqlKeyWhere If Not IsNumeric(x_contactid) Then LoadData = False Exit Function End If sFilter = Replace(sFilter, "@contactid", AdjustSql(x_contactid)) ' Replace key value sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "") Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sSql, conn If rs.Eof Then LoadData = False Else LoadData = True rs.MoveFirst ' Get the field contents x_contactid = rs("contactid") x_Name = rs("Name") x_Email = rs("Email") x_mobile = rs("mobile") x_origin = rs("origin") x_destination = rs("destination") x_departure = rs("departure") x_dateArrival = rs("dateArrival") x_Reference = rs("Reference") x_personstraveling = rs("personstraveling") x_trip_requirement = rs("trip_requirement") End If rs.Close Set rs = Nothing End Function %> <% '------------------------------------------------------------------------------- ' Function AddData ' - Add Data ' - Variables used: field variables Function AddData() On Error Resume Next Dim rs, sSql, sFilter Dim rsnew Dim bCheckKey, sSqlChk, sWhereChk sFilter = ewSqlKeyWhere ' Check for duplicate key bCheckKey = True If x_contactid = "" Or IsNull(x_contactid) Then bCheckKey = False Else sFilter = Replace(sFilter, "@contactid", AdjustSql(x_contactid)) ' Replace key value End If If Not IsNumeric(x_contactid) Then bCheckKey = False End If If bCheckKey Then sSqlChk = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "") Set rsChk = conn.Execute(sSqlChk) If Err.Number <> 0 Then Session(ewSessionMessage) = Err.Description rsChk.Close Set rsChk = Nothing AddData = False Exit Function ElseIf Not rsChk.Eof Then Session(ewSessionMessage) = "Duplicate value for primary key" rsChk.Close Set rsChk = Nothing AddData = False Exit Function End If rsChk.Close Set rsChk = Nothing End If ' Add New Record sFilter = "(0 = 1)" sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "") Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = 2 rs.Open sSql, conn, 1, 2 If Err.Number <> 0 Then Session(ewSessionMessage) = Err.Description rs.Close Set rs = Nothing AddData = False Exit Function End If rs.AddNew ' Field Name sTmp = Trim(x_Name) If Trim(sTmp) = "" Then sTmp = Null rs("Name") = sTmp ' Field Email sTmp = Trim(x_Email) If Trim(sTmp) = "" Then sTmp = Null rs("Email") = sTmp ' Field mobile sTmp = Trim(x_mobile) If Trim(sTmp) = "" Then sTmp = Null rs("mobile") = sTmp ' Field origin sTmp = Trim(x_origin) If Trim(sTmp) = "" Then sTmp = Null rs("origin") = sTmp ' Field destination sTmp = Trim(x_destination) If Trim(sTmp) = "" Then sTmp = Null rs("destination") = sTmp ' Field departure sTmp = Trim(x_departure) If Trim(sTmp) = "" Then sTmp = Null rs("departure") = sTmp ' Field dateArrival sTmp = Trim(x_dateArrival) If Trim(sTmp) = "" Then sTmp = Null rs("dateArrival") = sTmp ' Field Reference sTmp = Trim(x_Reference) If Trim(sTmp) = "" Then sTmp = Null rs("Reference") = sTmp ' Field personstraveling sTmp = Trim(x_personstraveling) If Trim(sTmp) = "" Then sTmp = Null rs("personstraveling") = sTmp ' Field trip_requirement sTmp = Trim(x_trip_requirement) If Trim(sTmp) = "" Then sTmp = Null rs("trip_requirement") = sTmp ' Call recordset inserting event If Recordset_Inserting(rs) Then ' Clone new rs object Set rsnew = CloneRs(rs) rs.Update If Err.Number <> 0 Then Session(ewSessionMessage) = Err.Description AddData = False Else AddData = True End If Else rs.CancelUpdate AddData = False End If rs.Close Set rs = Nothing ' Call recordset inserted event If AddData Then Call Recordset_Inserted(rsnew) End If rsnew.Close Set rsnew = Nothing End Function '------------------------------------------------------------------------------- ' Recordset inserting event Function Recordset_Inserting(rsnew) On Error Resume Next ' Please enter your customized codes here Recordset_Inserting = True End Function '------------------------------------------------------------------------------- ' Recordset inserted event Sub Recordset_Inserted(rsnew) On Error Resume Next Dim table table = "contact" ' Get key value Dim sKey sKey = "" If sKey <> "" Then sKey = sKey & "," sKey = sKey & rsnew.Fields("contactid") x_contactid = rsnew.Fields("contactid") End Sub %>