swordfishsoup
asked on
redirect page if quantity entered in form is less than recordset value
I have a product page with an 'add to cart' form. All works ok except I'm trying to check the stock level (via the RsStock recordset) and if the quantity in the form is more than the stock then redirects to out of stock page.
All I seem to achieve is the out of stock page redirect even though I know the stock is available.
I took outthe close section for the recordset as I kept getting an Object required with the line number referencing the close at te bottom of the page. I guessed that was because I'm using the Recordsets (Price and Stock) durin the process of form submission and not before it like the other recordsets on the page which aren't causing a problem.
I've highlighted wher the relevant parts of the code are in the page below.
In english I just want to say if the form value is more than the stock value then redirect or else carry on and add to cart.
Thanks for your help
Dave
All I seem to achieve is the out of stock page redirect even though I know the stock is available.
I took outthe close section for the recordset as I kept getting an Object required with the line number referencing the close at te bottom of the page. I guessed that was because I'm using the Recordsets (Price and Stock) durin the process of form submission and not before it like the other recordsets on the page which aren't causing a problem.
I've highlighted wher the relevant parts of the code are in the page below.
In english I just want to say if the form value is more than the stock value then redirect or else carry on and add to cart.
Thanks for your help
Dave
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="WA_eCart/WA_eCart_Definition_VB.asp" -->
<!--#include file="WA_eCart/magecart_VB.asp" -->
<!--#include file="Connections/MagicalRooms.asp" -->
<%
Dim RsImageFeatured__MMColParam
RsImageFeatured__MMColParam = "393"
If (Request.QueryString("ProdID") <> "") Then
RsImageFeatured__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsImageFeatured
Dim RsImageFeatured_cmd
Dim RsImageFeatured_numRows
Set RsImageFeatured_cmd = Server.CreateObject ("ADODB.Command")
RsImageFeatured_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsImageFeatured_cmd.CommandText = "SELECT tblProducts.ProdName, tblImages.Image FROM tblProducts LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID WHERE (((tblImages.Featured)=True) AND ((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblImages.Image"
RsImageFeatured_cmd.Prepared = true
RsImageFeatured_cmd.Parameters.Append RsImageFeatured_cmd.CreateParameter("param1", 5, 1, -1, RsImageFeatured__MMColParam) ' adDouble
Set RsImageFeatured = RsImageFeatured_cmd.Execute
RsImageFeatured_numRows = 0
%>
<%
Dim RsImages__MMColParam
RsImages__MMColParam = "393"
If (Request.QueryString("ProdID") <> "") Then
RsImages__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsImages
Dim RsImages_cmd
Dim RsImages_numRows
Set RsImages_cmd = Server.CreateObject ("ADODB.Command")
RsImages_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsImages_cmd.CommandText = "SELECT tblProducts.ProdName, tblImages.Image FROM tblProducts LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID WHERE (((tblImages.Featured)=False) AND ((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblImages.Image"
RsImages_cmd.Prepared = true
RsImages_cmd.Parameters.Append RsImages_cmd.CreateParameter("param1", 5, 1, -1, RsImages__MMColParam) ' adDouble
Set RsImages = RsImages_cmd.Execute
RsImages_numRows = 0
%>
<%
Dim RsDetail__MMColParam
RsDetail__MMColParam = "393"
If (Request.QueryString("ProdID") <> "") Then
RsDetail__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsDetail
Dim RsDetail_cmd
Dim RsDetail_numRows
Set RsDetail_cmd = Server.CreateObject ("ADODB.Command")
RsDetail_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsDetail_cmd.CommandText = "SELECT tblProducts.ProdName, tblProducts.ProdLongDesc, tblAvailColours.AvailColourName, tblSizeGroup.SizeName, tblPrice.Price, tblPrice.PriceDiscMin, tblPrice.PriceDiscPrice, tblStock.Quantity, tblSizeGroup.SizeGroupID, tblAvailColours.AvailColourID, tblPrice.PriceID, tblProducts.ProdID, tblProducts.ProdShortDesc FROM ((tblProducts LEFT JOIN (tblSizeGroup RIGHT JOIN (tblStock LEFT JOIN tblPrice ON tblStock.StockProdID = tblPrice.PriceProdID) ON tblSizeGroup.SizeGroupID = tblPrice.PriceSizeID) ON tblProducts.ProdID = tblStock.StockProdID) LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID) LEFT JOIN (tblAvailColours RIGHT JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblProducts.ProdLongDesc, tblAvailColours.AvailColourName, tblSizeGroup.SizeName, tblPrice.Price, tblPrice.PriceDiscMin, tblPrice.PriceDiscPrice, tblStock.Quantity, tblSizeGroup.SizeGroupID, tblAvailColours.AvailColourID, tblPrice.PriceID, tblProducts.ProdID, tblProducts.ProdShortDesc"
RsDetail_cmd.Prepared = true
RsDetail_cmd.Parameters.Append RsDetail_cmd.CreateParameter("param1", 5, 1, -1, RsDetail__MMColParam) ' adDouble
Set RsDetail = RsDetail_cmd.Execute
RsDetail_numRows = 0
%>
<%
Dim RsColour__MMColParam
RsColour__MMColParam = "392"
If (Request.QueryString("ProdID") <> "") Then
RsColour__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsColour
Dim RsColour_cmd
Dim RsColour_numRows
Set RsColour_cmd = Server.CreateObject ("ADODB.Command")
RsColour_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsColour_cmd.CommandText = "SELECT Count(tblProdColours.ProdAvailColour) AS CountOfProdAvailColour FROM tblProducts INNER JOIN (tblAvailColours INNER JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProdColours.ProdProdID)= ?))"
RsColour_cmd.Prepared = true
RsColour_cmd.Parameters.Append RsColour_cmd.CreateParameter("param1", 5, 1, -1, RsColour__MMColParam) ' adDouble
Set RsColour = RsColour_cmd.Execute
RsColour_numRows = 0
%>
<%
Dim RsColourName__MMColParam
RsColourName__MMColParam = "392"
If (Request.QueryString("ProdID") <> "") Then
RsColourName__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsColourName
Dim RsColourName_cmd
Dim RsColourName_numRows
Set RsColourName_cmd = Server.CreateObject ("ADODB.Command")
RsColourName_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsColourName_cmd.CommandText = "SELECT tblAvailColours.AvailColourName FROM tblProducts INNER JOIN (tblAvailColours INNER JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProdColours.ProdProdID)= ? ))"
RsColourName_cmd.Prepared = true
RsColourName_cmd.Parameters.Append RsColourName_cmd.CreateParameter("param1", 5, 1, -1, RsColourName__MMColParam) ' adDouble
Set RsColourName = RsColourName_cmd.Execute
RsColourName_numRows = 0
%>
<%
Dim HLooper1__numRows
HLooper1__numRows = -2
Dim HLooper1__index
HLooper1__index = 0
RsImages_numRows = RsImages_numRows + HLooper1__numRows
%>
<% 'This is where it all kicks off ************************************************************************************** %>
<%
' WA eCart AddToCart
if (cStr(Request.Form("magecart_1_ATC")) <> "" OR cStr(Request.Form("magecart_1_ATC.x")) <> "") then
%>
<%
Dim RsPrice__ParamProdID
RsPrice__ParamProdID = "392"
If (Request.Form("magecart_1_ID_Add") <> "") Then
RsPrice__ParamProdID = Request.Form("magecart_1_ID_Add")
End If
%>
<%
Dim RsPrice__ParamSizeName
RsPrice__ParamSizeName = "Age 8"
If (Request.Form("magecart_1_Size_Add") <> "") Then
RsPrice__ParamSizeName = Request.Form("magecart_1_Size_Add")
End If
%>
<%
Dim RsPrice
Dim RsPrice_cmd
Dim RsPrice_numRows
Set RsPrice_cmd = Server.CreateObject ("ADODB.Command")
RsPrice_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsPrice_cmd.CommandText = "SELECT tblPrice.Price FROM tblSizeGroup RIGHT JOIN tblPrice ON tblSizeGroup.SizeGroupID = tblPrice.PriceSizeID WHERE (((tblPrice.PriceProdID)= ? ) AND ((tblSizeGroup.SizeName)= ?)) GROUP BY tblPrice.Price"
RsPrice_cmd.Prepared = true
RsPrice_cmd.Parameters.Append RsPrice_cmd.CreateParameter("param1", 5, 1, -1, RsPrice__ParamProdID) ' adDouble
RsPrice_cmd.Parameters.Append RsPrice_cmd.CreateParameter("param2", 200, 1, 255, RsPrice__ParamSizeName) ' adVarChar
Set RsPrice = RsPrice_cmd.Execute
RsPrice_numRows = 0
%>
<%
Dim RsStock__ParamProdID
RsStock__ParamProdID = "392"
If (Request.Form("magecart_1_ID_Add") <> "") Then
RsStock__ParamProdID = Request.Form("magecart_1_ID_Add")
End If
%>
<%
Dim RsStock__ParamColour
RsStock__ParamColour = "Hot Pink"
If (Request.Form("magecart_1_Colour_Add") <> "") Then
RsStock__ParamColour = Request.Form("magecart_1_Colour_Add")
End If
%>
<%
Dim RsStock__ParamSize
RsStock__ParamSize = "Age 8"
If (Request.Form("magecart_1_Size_Add") <> "") Then
RsStock__ParamSize = Request.Form("magecart_1_Size_Add")
End If
%>
<%
Dim RsStock
Dim RsStock_cmd
Dim RsStock_numRows
Set RsStock_cmd = Server.CreateObject ("ADODB.Command")
RsStock_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsStock_cmd.CommandText = "SELECT tblStock.Quantity, tblProducts.ProdName, tblStock.StockID FROM tblProducts RIGHT JOIN ((tblStock LEFT JOIN tblSizeGroup ON tblStock.StockSizeID = tblSizeGroup.SizeGroupID) LEFT JOIN tblAvailColours ON tblStock.StockColourID = tblAvailColours.AvailColourID) ON tblProducts.ProdID = tblStock.StockProdID WHERE (((tblStock.StockProdID)= ? ) AND ([tblAvailColours].[AvailColourName]= ? ) AND ([tblSizegroup].[SizeName]= ? )) GROUP BY tblStock.Quantity, tblProducts.ProdName, tblStock.StockID"
RsStock_cmd.Prepared = true
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param1", 5, 1, -1, RsStock__ParamProdID) ' adDouble
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param2", 200, 1, 255, RsStock__ParamColour) ' adVarChar
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param3", 200, 1, 255, RsStock__ParamSize) ' adVarChar
Set RsStock = RsStock_cmd.Execute
RsStock_numRows = 0
%>
<% Dim OutOfStock
OutOfStock = "out_of_stock.asp"
%>
<% Dim StockLevel
StockLevel = (RsStock.Fields.Item("Quantity").Value) %>
<% 'This is where The from is processed ************************************************************************************** %>
<%
ATC_itemID = cStr(Request.Form("magecart_1_ID_Add"))
ATC_AddIfIn = 0
ATC_RedirectAfter = "bag.asp"
ATC_RedirectIfIn = ""
ATC_itemName = "" & cStr(Request.Form("magecart_1_Name_Add")) & ""' column binding
ATC_itemDescription = "" & cStr(Request.Form("magecart_1_Description_Add")) & ""' column binding
ATC_itemWeight = cDbl("0")' column binding
ATC_itemQuantity = "" & cStr(Request.Form("magecart_1_Quantity_Add")) & ""' column binding
ATC_itemPrice = (RsPrice.Fields.Item("Price").Value) ' column binding
ATC_itemColour = "" & cStr(Request.Form("magecart_1_Colour_Add")) & ""' column binding
ATC_itemSize = "" & cStr(Request.Form("magecart_1_Size_Add")) & ""' column binding
if cStr(Request.Form("magecart_1_Quantity_Add")) > StockLevel then
Response.Redirect(OutOfStock)
else
if (IsNumeric(ATC_itemQuantity) AND ATC_itemQuantity <> 0) then
set magecart = magecart_AddToCart(ATC_AddIfIn, ATC_RedirectIfIn, ATC_itemID, ATC_itemName, ATC_itemDescription, ATC_itemWeight, ATC_itemQuantity, ATC_itemPrice, ATC_itemColour, ATC_itemSize)
if (ATC_RedirectAfter <> "" AND magecart_redirStr = "") then
magecart_redirStr = ATC_RedirectAfter
end if
Session("WAEC_ContinueRedirect") = cStr(Request.ServerVariables("Script_Name")) & "?" & cStr(Request.QueryString())
end if
end if
end if
%>
'<%
'RsPrice.Close()
'Set RsPrice = Nothing %>
'<%
'RsStock.Close()
'Set RsStock = Nothing
'%>
<%
' WA eCart Redirect
if (magecart_redirStr <> "") then
Response.Redirect(magecart_redirStr)
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/master1.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="magicalrooms.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<!-- InstanceParam name="bag" type="boolean" value="true" --><!-- InstanceParam name="leftNav" type="boolean" value="true" --><!-- InstanceParam name="admin nav" type="boolean" value="false" --><!-- InstanceParam name="site nav" type="boolean" value="true" -->
</head>
<body onload="MM_preloadImages('img/images/wish_list_selected_03.gif','img/images/log_in_selected_03.gif','img/images/register_selected_03.gif','img/images/delivery_selected_03.gif','img/images/locator_selected_03.gif','img/images/help_selected_03.gif','img/images/voucher_selected_03.gif')">
<div id="container">
<div id="banner">
<div id="logo"></div>
<!--#include file="keyword_search.asp" -->
<div id="tabs"><img src="img/images/full_tabs_03.gif" name="fulltabs" width="467" height="23" border="0" usemap="#tab" id="fulltabs" />
<map name="tab" id="tab">
<area shape="rect" coords="2,2,56,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/wish_list_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
<area shape="rect" coords="58,3,97,21" href="login.asp" onmouseover="MM_swapImage('fulltabs','','img/images/log_in_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
<area shape="rect" coords="99,3,146,21" href="register.asp" onmouseover="MM_swapImage('fulltabs','','img/images/register_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
<area shape="rect" coords="149,3,196,23" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/delivery_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
<area shape="rect" coords="200,3,316,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/locator_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
<area shape="rect" coords="319,5,350,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/help_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
<area shape="rect" coords="355,5,455,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/voucher_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
</map>
</div>
</div>
<div id="mainpage">
<div id="leftnav">
<script type="text/javascript" language="JavaScript" src="Scripts/drop.js">
</script>
<!--#include file="nav.asp" -->
<!--#include file="bag_display.asp"-->
</div>
<!-- InstanceBeginEditable name="contentarea" --><div id="content">
<div id="detailImages">
<p><img src="download_detail.asp?id=<%=(RsImageFeatured.Fields.Item("Image").Value)%>&Width=150" alt="<%=(RsImageFeatured.Fields.Item("ProdName").Value)%>" hspace="5" vspace="5" border="0" align="center" /> </p>
<p>
<table>
<%
startrw = 0
endrw = HLooper1__index
numberColumns = 2
numrows = -1
while((numrows <> 0) AND (Not RsImages.EOF))
startrw = endrw + 1
endrw = endrw + numberColumns
%>
<tr align="center" valign="top">
<%
While ((startrw <= endrw) AND (Not RsImages.EOF))
%>
<td><img src="download_detail_thumbs.asp?id=<%=(RsImages.Fields.Item("Image").Value)%>&Width=70" alt="<%=(RsImages.Fields.Item("ProdName").Value)%>" hspace="5" vspace="5" border="0" align="center" /> </td>
<%
startrw = startrw + 1
RsImages.MoveNext()
Wend
%>
</tr>
<%
numrows=numrows-1
Wend
%>
</table>
</div>
<div id="detailDetails">
<br />
<h1><%=(RsDetail.Fields.Item("ProdName").Value)%></h1>
<p><%=(RsDetail.Fields.Item("ProdLongDesc").Value)%> </p>
</div>
<div id="addtobag">
<p>Choose your required colour and size and select a quantity:</p>
<form name="magecart_1_ATC_<%=RsDetail.Fields("ProdID").value%>" method="POST" action="<%=cStr(Request.ServerVariables("SCRIPT_NAME"))%><%=WA_eCart_IIf((Request.ServerVariables("QUERY_STRING") <> ""), "?" & Request.ServerVariables("QUERY_STRING"), "")%>">
<input type="hidden" name="magecart_1_ID_Add" value="<%=(RsDetail.Fields.Item("ProdID").Value)%>" />
<input type="hidden" name="magecart_1_Name_Add" value="<%=(RsDetail.Fields.Item("ProdName").Value)%>" />
<input type="hidden" name="magecart_1_Description_Add" value="<%=(RsDetail.Fields.Item("ProdShortDesc").Value)%>" />
<input type="text" name="magecart_1_Quantity_Add" value="1" size="4" />
<% If (RsColour.Fields.Item("CountOfProdAvailColour").Value)>= 2 Then %>
<select name="magecart_1_Colour_Add" id="magecart_1_Colour_Add">
<%
While (NOT RsColourName.EOF)
%><option value="<%=(RsColourName.Fields.Item("AvailColourName").Value)%>"><%=(RsColourName.Fields.Item("AvailColourName").Value)%></option><%
RsColourName.MoveNext()
Wend
If (RsColourName.CursorType > 0) Then
RsColourName.MoveFirst
Else
RsColourName.Requery
End If
%>
</select>
<% Else %>
<input name="magecart_1_Colour_Add" type="hidden" value="<%=(RsDetail.Fields.Item("AvailColourName").Value)%>" />
<% End If %>
<% If Not(RsDetail.Fields.Item("SizeName").Value) = "None" Then %>
<select name="magecart_1_Size_Add" id="magecart_1_Size_Add">
<%
While (NOT RsDetail.EOF)
%>
<option value="<%=(RsDetail.Fields.Item("SizeName").Value)%>"><%=(RsDetail.Fields.Item("SizeName").Value)%></option>
<%
RsDetail.MoveNext()
Wend
If (RsDetail.CursorType > 0) Then
RsDetail.MoveFirst
Else
RsDetail.Requery
End If
%>
</select>
<% Else %>
<input name="magecart_1_Size_Add" type="hidden" value="<%=(RsDetail.Fields.Item("SizeName").Value)%>" />
<% End If %>
<input type="image" src="WA_eCart/Images/Pacifica/Btn2_EN_addtocart.gif" border="0" value="Add to Cart" name="magecart_1_ATC">
</form>
<p><br />
</p>
</div>
<br />
</p>
</div>
<!-- InstanceEndEditable --></div>
<div class="footer" id="footer"><a href="page.html">How To Find Us</a> <a href="page.html">Terms & Conditions</a> - <a href="page.html">Privacy
Policy</a> - Returns - Links - Customer Feedback<br />
© Copyright Magical Rooms 2007</div>
</div></body>
<!-- InstanceEnd --></html>
<%
RsImageFeatured.Close()
Set RsImageFeatured = Nothing
%>
<%
RsImages.Close()
Set RsImages = Nothing
%>
<%
RsDetail.Close()
Set RsDetail = Nothing
%>
<%
RsColour.Close()
Set RsColour = Nothing
%>
<%
RsColourName.Close()
Set RsColourName = Nothing
%>
'<%
'RsPrice.Close()
'Set RsPrice = Nothing
'%>
'<%
'RsStock.Close()
'Set RsStock = Nothing
'%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
ASKER
CCongdon, out of curiosity, is it right that I had to comment out the recordset close section that dreamweaver inserts (very bottom of the page) to get this to work?
Yes and no. You don't *have* to close out your objects when you are done with them, IIS will perform housecleaning sooner or later. However, it is good practice to do so.
That being said, you could put in a sub like this at the top of the page:
Sub dbCleanUp()
rsRecordset1.Close()
rsRecordset2.Close()
connConnection.Close()
Set rsRecordset1 = Nothing
Set rsRecordset2 = Nothing
Set connConnection = Nothing
End Sub
Then, when you are leaving the page (either by re-direct or simply at the end of the page) just call the Sub...
if cInt(Request.Form("magecar t_1_Quanti ty_Add")) > StockLevel then
dbCleanUp()
Response.Redirect(OutOfSto ck)
Now, I'm sure you noticed one penalty to commenting out the auto-inserted clean up at the bottom. Dreamweaver might not let you edit the recordset or connections using its built in behaviors anymore! This gets annoying. I loathe when I try to clean up dreamweaver's excessive/extraneous coding and it costs me the ease of editing. Most of the time anymore, I just manually write my DB opening/manipulating scripts.
Another alternative to the Sub idea is to do this:
If IsObject(rsRecordset1) Then
rsRecordset1.Close()
Set rsRecordset1 = Nothing
End If
I've done that a few times where the dbCleanUp sub-routine may not work as well. Sometimes you may have a lot of objects. However, depending on how your code flows, some of the objets may be closed before the end of the page or may never have been opened. Checking to see if they exist as objects and closing them if they do is a good way to enforce cleanup at the bottom of the page.
That being said, you could put in a sub like this at the top of the page:
Sub dbCleanUp()
rsRecordset1.Close()
rsRecordset2.Close()
connConnection.Close()
Set rsRecordset1 = Nothing
Set rsRecordset2 = Nothing
Set connConnection = Nothing
End Sub
Then, when you are leaving the page (either by re-direct or simply at the end of the page) just call the Sub...
if cInt(Request.Form("magecar
dbCleanUp()
Response.Redirect(OutOfSto
Now, I'm sure you noticed one penalty to commenting out the auto-inserted clean up at the bottom. Dreamweaver might not let you edit the recordset or connections using its built in behaviors anymore! This gets annoying. I loathe when I try to clean up dreamweaver's excessive/extraneous coding and it costs me the ease of editing. Most of the time anymore, I just manually write my DB opening/manipulating scripts.
Another alternative to the Sub idea is to do this:
If IsObject(rsRecordset1) Then
rsRecordset1.Close()
Set rsRecordset1 = Nothing
End If
I've done that a few times where the dbCleanUp sub-routine may not work as well. Sometimes you may have a lot of objects. However, depending on how your code flows, some of the objets may be closed before the end of the page or may never have been opened. Checking to see if they exist as objects and closing them if they do is a good way to enforce cleanup at the bottom of the page.
ASKER
Thanks for taking the trouble to explain that. I'll add the sub as I've just had to restart my PC as Local host seemed to be having an issue and taking forever to open the next page after a link! It coud be connected I guess..
Thanks again
Thanks again
ASKER
Have a good day