Hi All,
I am trying to do a sub procedure to update the table, so that I can use it in many instances without replicating the code. However I have never used Sub Procedures before and so I am not very familiar with them. Here is my code, which is not working. Can anybody help me out?
<!---------------------MODIFY CLUB INFO ---------------------------------->
<%
if var1 = "ModifyTable" then
Dim Address1,Address2,Address3,Tel,Fax,Email,rsModifyClub,sqlModifyClub,sql1,sql2,sql3,intHowLong,WherePos,ClubID
'********** Replace Single Quotes with Double Single Quotes to avoid sql1 errors
function KillQuotes(theString)
KillQuotes = Replace(theString,"'","''"
'SYNTAX -- Replace(expression, find, replacewith)
end function
Address1 = Request.Form("address1"
Address2 = Request.Form("address2"
Address3 = Request.Form("address3"
Tel = Request.Form("tel"
Fax = Request.Form("fax"
Email = Request.Form("email"
ClubID = Request.Form("ClubID"
'*** Create a recordset to modify the database
Set rsModifyClub=Server.CreateObject("ADODB.Recordset"
rsModifyClub.ActiveConnection = cnn
'****** The update clause
if Address1 <> "''" then
sqlModifyClub = sqlModifyClub & "clubAddress1 = '" & KillQuotes(address1) & "'" & ", "
end if
if Address2 <> "''" then
sqlModifyClub = sqlModifyClub & "clubAddress2 = '" & KillQuotes(address2) & "'" & ", "
end if
if Address3 <> "''" then
sqlModifyClub = sqlModifyClub & "clubAddress3 = '" & KillQuotes(address3) & "'" & ", "
end if
if Tel <> "''" then
sqlModifyClub = sqlModifyClub & "clubTelNo = " & KillQuotes(Tel) & ", "
end if
if Fax <> "''" then
sqlModifyClub = sqlModifyClub & "clubFaxNo = " & KillQuotes(Fax) & ", "
end if
if Email <> "''" then
sqlModifyClub = sqlModifyClub & "clubEmail = '" & KillQuotes(Email) & "'" & ", "
end if
sql = sqlModifyClub
table = clubInfo
tableID = clubID
formID = ClubID
call UpdateRecord()
%>
<--------- and then I have the Sub Procedure -------->
<%
sub UpdateRecord()
Dim sql,sql1,sql2,sql3,intHowLong,WherePos,table,tableID,formID
'****** The update clause
sql = "UPDATE " & table & " SET "
sql = sql & sql
'*** Replace the last comma
sql= sql & "WHERE " & tableID = formID & "; "
'*** Procedure to remove the last comma before the where for the sql to work
'--- determine the length of the string
intHowLong = Len(sql)
'--- determine in which position is the WHERE clause
WherePos = InStr(sql, "WHERE"
'--- extract the first part of the sql
sql1 = Mid(sql, 1, WherePos-3)
'--- extract the second part of the sql. Number of characters in this case will always be 20 since the
'--- WHERE clause is always the same
sql2 = Right(sql, intHowLong - WherePos+1)
'--- Now concatenate the 2 statements to form the proper sql
sql3 = sql1 & " " & sql2
response.Write(sql3)
'cnn.execute (sql3)
end sub
%>
Can you tell me what I have wrong please?
Thanks for your help
I am trying to do a sub procedure to update the table, so that I can use it in many instances without replicating the code. However I have never used Sub Procedures before and so I am not very familiar with them. Here is my code, which is not working. Can anybody help me out?
<!---------------------MODIFY CLUB INFO ---------------------------------->
<%
if var1 = "ModifyTable" then
Dim Address1,Address2,Address3,Tel,Fax,Email,rsModifyClub,sqlModifyClub,sql1,sql2,sql3,intHowLong,WherePos,ClubID
'********** Replace Single Quotes with Double Single Quotes to avoid sql1 errors
function KillQuotes(theString)
KillQuotes = Replace(theString,"'","''"
end function
Address1 = Request.Form("address1"
Address2 = Request.Form("address2"
Address3 = Request.Form("address3"
Tel = Request.Form("tel"
Fax = Request.Form("fax"
Email = Request.Form("email"
ClubID = Request.Form("ClubID"
'*** Create a recordset to modify the database
Set rsModifyClub=Server.CreateObject("ADODB.Recordset"
rsModifyClub.ActiveConnection = cnn
'****** The update clause
if Address1 <> "''" then
sqlModifyClub = sqlModifyClub & "clubAddress1 = '" & KillQuotes(address1) & "'" & ", "
end if
if Address2 <> "''" then
sqlModifyClub = sqlModifyClub & "clubAddress2 = '" & KillQuotes(address2) & "'" & ", "
end if
if Address3 <> "''" then
sqlModifyClub = sqlModifyClub & "clubAddress3 = '" & KillQuotes(address3) & "'" & ", "
end if
if Tel <> "''" then
sqlModifyClub = sqlModifyClub & "clubTelNo = " & KillQuotes(Tel) & ", "
end if
if Fax <> "''" then
sqlModifyClub = sqlModifyClub & "clubFaxNo = " & KillQuotes(Fax) & ", "
end if
if Email <> "''" then
sqlModifyClub = sqlModifyClub & "clubEmail = '" & KillQuotes(Email) & "'" & ", "
end if
sql = sqlModifyClub
table = clubInfo
tableID = clubID
formID = ClubID
call UpdateRecord()
%>
<--------- and then I have the Sub Procedure -------->
<%
sub UpdateRecord()
Dim sql,sql1,sql2,sql3,intHowLong,WherePos,table,tableID,formID
'****** The update clause
sql = "UPDATE " & table & " SET "
sql = sql & sql
'*** Replace the last comma
sql= sql & "WHERE " & tableID = formID & "; "
'*** Procedure to remove the last comma before the where for the sql to work
'--- determine the length of the string
intHowLong = Len(sql)
'--- determine in which position is the WHERE clause
WherePos = InStr(sql, "WHERE"
'--- extract the first part of the sql
sql1 = Mid(sql, 1, WherePos-3)
'--- extract the second part of the sql. Number of characters in this case will always be 20 since the
'--- WHERE clause is always the same
sql2 = Right(sql, intHowLong - WherePos+1)
'--- Now concatenate the 2 statements to form the proper sql
sql3 = sql1 & " " & sql2
response.Write(sql3)
'cnn.execute (sql3)
end sub
%>
Can you tell me what I have wrong please?
Thanks for your help