I've got the first two pages working as shown below, but now I have a problem validating the checkboxes (per GroupID) from page 2, to make sure the user has selected at least one checkbox from each generated GroupID list of checkboxes (prior to submitting to add_supplier.asp) What would the code be to check these? may be only one GroupID or 20 GroupID's to check.
Here is the code for my first and second pages.
***************************************************
The code for "Registration.asp", which is the First page of form:
<% @LANGUAGE=VBscript %>
<% Option Explicit %>
<%
Response.Buffer = True
Dim dbConn 'Common Database connection
Dim rsConn 'Common recordset object
Dim strSQL 'SQL string constructor
'Get the database connection
Set dbConn = Server.CreateObject( "ADODB.Connection" )
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "Purchasing.mdb" ) & ";"
'Get the main categories from the (seala.mdb) database; (Main Categories Table)
strSQL = "SELECT GroupID, Description FROM [Main Categories] ORDER BY Description"
Set rsConn = dbConn.Execute( strSQL )
If rsConn.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
%>
<html>
<head>
<title>Select Main Category</title>
</head>
<body>
<table align="center"><tbody>
<td colspan="2" class="thead">Select Main Categories</td>
<form name="maincat" action="Commodites.asp" method="post">
<%
'Make our way through the main categories and write the data as we go
While NOT rsConn.EOF
%>
<tr><td><%=rsConn("Description"
%></td>
<td><input type="checkbox" name="chkbox<%=rsConn("GroupID"
%>"></td>
</tr>
<%
'Next record
rsConn.MoveNext
Wend
%>
<tr><td align="center" colspan="2">
<input type="submit" value="Submit Form"> <input type="reset" value="Reset Data">
</td></tr>
</form>
</tbody></table>
</body>
</html>
<%
'Clean up database objects
Set rsConn = Nothing
dbConn.Close
Set dbConn = Nothing
%>
***************************************************
The code for "Commodities.asp" which is the second page of form:
<% @LANGUAGE=VBscript %>
<% Option Explicit %>
<html>
<head>
<title>Select sub categories</title>
</head>
<body>
<form action="add_supplier.asp" method="post" name="subcategory">
<%
Response.Buffer = True
Dim dbConn 'Common Database connection
Dim rsMain 'Common recordset object
Dim rsSub
Dim strSQL 'SQL string constructor
Dim fld
Dim counter
Dim ArrayCheck(100)
Dim ArraySize
ArraySize = 0
'Get the database connection
Set dbConn = Server.CreateObject( "ADODB.Connection" )
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "seala.mdb" ) & ";"
'Get the main categories from the database. All we need at the moment is the identities
strSQL = "SELECT GroupID FROM [Main Categories]"
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
'Scan the form looking for checked boxes
While NOT rsMain.EOF
fld = Request.Form( "chkbox" & rsMain("GroupID"
) 'Get the field from the form
If NOT (fld = False) Then 'Was the box checked
ArrayCheck( ArraySize ) = rsMain("GroupID"
'Add the GroupID to the array
ArraySize = ArraySize + 1 'Increment the array size
End If
rsMain.MoveNext 'Next database record
Wend
Set rsMain = Nothing
'Check that something was selected
If ArraySize = 0 Then
Response.Redirect "NOTHINGSELECTED.ASP"
End If
'Make the SQL string for the group selection
strSQL = "SELECT GroupID, Description FROM [Main Categories] WHERE "
'Make our way through the array making the selections we want
For counter = 0 To ArraySize - 1
If counter > 0 Then strSQL = strSQL & " OR " 'Put the OR in if required
strSQL = strSQL & "(GroupID=" & ArrayCheck(counter) & "
"
Next
'Now sort the output
strSQL = strSQL & " ORDER BY Description"
'Get the sorted records we want from the database
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
'Start the main category display loop
While NOT rsMain.EOF
'Write the table header
Response.Write( "<table align=""center"">" & vbCrLf )
'Write the title of the current selection block (or main category description)
Response.Write( "<tr><td colspan=""2""><h1>" & rsMain("Description"
& "</h1></td></tr>" & vbCrLf )
'--------------------------- BEGIN OF SUB-CATEGORY SECTION -------------------------
'Make the SQL string. We need all the categories that belong to the current main group
'and sort them into alphabetical order
strSQL = "SELECT CategoryID, Description FROM [Sub Categories] " & _
"WHERE GroupID=" & rsMain("GroupID" ) & _
" ORDER BY Description"
'Open the recordset
Set rsSub = dbConn.Execute( strSQL )
'Is there actually anything here
If NOT rsSub.EOF Then
'Start the scan loop
While NOT rsSub.EOF
'This is pretty much the same thing as in category.asp
%>
<tr><td><%=rsSub("Description"
%></td>
<td><input type="checkbox" name="catbox<%=rsSub("CategoryID"
%>"></td>
</tr>
<%
rsSub.MoveNext
Wend
End If
'Clean up recordset object
Set rsSub = Nothing
'---------------------------- END OF SUB-CATEGORY SECTION --------------------------
'End of the category table
Response.Write( "</table><br><br>" & vbCrLf )
rsMain.MoveNext
Wend
'--------- Display the submit and reset buttons ------------------------
%>
<div align="center">
<input type="submit" value="Submit Form"> <input type="Reset" value="Reset Form">
</div>
</form>
</body>
</html>
<%
'Clean up database
dbConn.Close
Set dbConn = Nothing
%>
****************************************************
"add_supplier.asp" will process the data from page 1 and page 2 and update a table (tblWeb_Supplier) in an access db called(Purchasing.mdb). Not sure if you need anything else, but any help would be appreciated!
Here is the code for my first and second pages.
***************************************************
The code for "Registration.asp", which is the First page of form:
<% @LANGUAGE=VBscript %>
<% Option Explicit %>
<%
Response.Buffer = True
Dim dbConn 'Common Database connection
Dim rsConn 'Common recordset object
Dim strSQL 'SQL string constructor
'Get the database connection
Set dbConn = Server.CreateObject( "ADODB.Connection" )
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "Purchasing.mdb" ) & ";"
'Get the main categories from the (seala.mdb) database; (Main Categories Table)
strSQL = "SELECT GroupID, Description FROM [Main Categories] ORDER BY Description"
Set rsConn = dbConn.Execute( strSQL )
If rsConn.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
%>
<html>
<head>
<title>Select Main Category</title>
</head>
<body>
<table align="center"><tbody>
<td colspan="2" class="thead">Select Main Categories</td>
<form name="maincat" action="Commodites.asp" method="post">
<%
'Make our way through the main categories and write the data as we go
While NOT rsConn.EOF
%>
<tr><td><%=rsConn("Description"
<td><input type="checkbox" name="chkbox<%=rsConn("GroupID"
</tr>
<%
'Next record
rsConn.MoveNext
Wend
%>
<tr><td align="center" colspan="2">
<input type="submit" value="Submit Form"> <input type="reset" value="Reset Data">
</td></tr>
</form>
</tbody></table>
</body>
</html>
<%
'Clean up database objects
Set rsConn = Nothing
dbConn.Close
Set dbConn = Nothing
%>
***************************************************
The code for "Commodities.asp" which is the second page of form:
<% @LANGUAGE=VBscript %>
<% Option Explicit %>
<html>
<head>
<title>Select sub categories</title>
</head>
<body>
<form action="add_supplier.asp" method="post" name="subcategory">
<%
Response.Buffer = True
Dim dbConn 'Common Database connection
Dim rsMain 'Common recordset object
Dim rsSub
Dim strSQL 'SQL string constructor
Dim fld
Dim counter
Dim ArrayCheck(100)
Dim ArraySize
ArraySize = 0
'Get the database connection
Set dbConn = Server.CreateObject( "ADODB.Connection" )
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "seala.mdb" ) & ";"
'Get the main categories from the database. All we need at the moment is the identities
strSQL = "SELECT GroupID FROM [Main Categories]"
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
'Scan the form looking for checked boxes
While NOT rsMain.EOF
fld = Request.Form( "chkbox" & rsMain("GroupID"
If NOT (fld = False) Then 'Was the box checked
ArrayCheck( ArraySize ) = rsMain("GroupID"
ArraySize = ArraySize + 1 'Increment the array size
End If
rsMain.MoveNext 'Next database record
Wend
Set rsMain = Nothing
'Check that something was selected
If ArraySize = 0 Then
Response.Redirect "NOTHINGSELECTED.ASP"
End If
'Make the SQL string for the group selection
strSQL = "SELECT GroupID, Description FROM [Main Categories] WHERE "
'Make our way through the array making the selections we want
For counter = 0 To ArraySize - 1
If counter > 0 Then strSQL = strSQL & " OR " 'Put the OR in if required
strSQL = strSQL & "(GroupID=" & ArrayCheck(counter) & "
Next
'Now sort the output
strSQL = strSQL & " ORDER BY Description"
'Get the sorted records we want from the database
Set rsMain = dbConn.Execute( strSQL )
If rsMain.EOF Then
Response.Redirect "MAJORERROR.ASP"
End If
'Start the main category display loop
While NOT rsMain.EOF
'Write the table header
Response.Write( "<table align=""center"">" & vbCrLf )
'Write the title of the current selection block (or main category description)
Response.Write( "<tr><td colspan=""2""><h1>" & rsMain("Description"
'--------------------------- BEGIN OF SUB-CATEGORY SECTION -------------------------
'Make the SQL string. We need all the categories that belong to the current main group
'and sort them into alphabetical order
strSQL = "SELECT CategoryID, Description FROM [Sub Categories] " & _
"WHERE GroupID=" & rsMain("GroupID" ) & _
" ORDER BY Description"
'Open the recordset
Set rsSub = dbConn.Execute( strSQL )
'Is there actually anything here
If NOT rsSub.EOF Then
'Start the scan loop
While NOT rsSub.EOF
'This is pretty much the same thing as in category.asp
%>
<tr><td><%=rsSub("Description"
<td><input type="checkbox" name="catbox<%=rsSub("CategoryID"
</tr>
<%
rsSub.MoveNext
Wend
End If
'Clean up recordset object
Set rsSub = Nothing
'---------------------------- END OF SUB-CATEGORY SECTION --------------------------
'End of the category table
Response.Write( "</table><br><br>" & vbCrLf )
rsMain.MoveNext
Wend
'--------- Display the submit and reset buttons ------------------------
%>
<div align="center">
<input type="submit" value="Submit Form"> <input type="Reset" value="Reset Form">
</div>
</form>
</body>
</html>
<%
'Clean up database
dbConn.Close
Set dbConn = Nothing
%>
****************************************************
"add_supplier.asp" will process the data from page 1 and page 2 and update a table (tblWeb_Supplier) in an access db called(Purchasing.mdb). Not sure if you need anything else, but any help would be appreciated!