Jump to content

MS Access, ASP Dreamweaver and Radio buttons


billylariviere@hotmail.com

Recommended Posts

Hi, ASP newbie here,I made a dynamic table which holds data from an Access database. I then added a radioButton at the end of each entry of the dynamic table. I was able to reference the radioButtons to the checkbox entry of my database so we can see which entry is selected. I selected only one checkbox in Access so I could make use of the checkboxes as a radiobutton group in ASP.I embedded the dynamic table in a form so when I choose a radio button (onchange), the form refreshes the page.There seems to be some missing information in my code since the radio buttons don't update my database.question: do I have to "tell" Access how my chechboxes should behave (as radioButtons), or do I work this through ASP?here's the code for the form part:

<form id="frmMessageChoisi" name="frmMessageChoisi" method="POST" action="<%=MM_editAction%>"> <table>   <tr>	<th>Date</th>	<th>Titre</th>	<th>Message</th>	<th>Selectionné</th>   </tr>  <% While ((Repeat1__numRows <> 0) AND (NOT rsMessageIndex.EOF)) %>	<tr>	 <td><a href="newsEditDetail.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "id=" & rsMessageIndex.Fields.Item("intMessageID").Value %>"><%=(rsMessageIndex.Fields.Item("dtePostDate").Value)%></a></td>	 <td><%=(rsMessageIndex.Fields.Item("txtMessageTitle").Value)%></td>	 <td><%=(rsMessageIndex.Fields.Item("memPostMessage").Value)%></td>	 <td>	  <div align="center">	   <input <%If (CStr((rsMessageIndex.Fields.Item("bitMessageChoisi").Value)) = CStr("True")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="radioChoisi" type="radio" dir="ltr" lang="fr" onchange="submit()"/>	  </div>	 </td>	</tr>	  <%	 	Repeat1__index=Repeat1__index+1	Repeat1__numRows=Repeat1__numRows-1	rsMessageIndex.MoveNext()    Wend  %>  </table>  <input type="hidden" name="MM_update" value="frmMessageChoisi" /> <input type="hidden" name="MM_recordId" value="<%= rsMessageChoisi.Fields.Item("intMessageID").Value %>" /> </form>

click here to see the page (login:test, pass:test)then the ASP code behind it:

 <%If (CStr(Request("MM_update")) = "frmMessageChoisi") Then  If (Not MM_abortEdit) Then	' execute the update	Dim MM_editCmd2	Set MM_editCmd2 = Server.CreateObject ("ADODB.Command")	MM_editCmd2.ActiveConnection = MM_connUsers_STRING	MM_editCmd2.CommandText = "UPDATE messages SET bitMessageChoisi = ? WHERE intMessageID = ?" 	MM_editCmd2.Prepared = true  MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("radioChoisi"), "-1", "0")) ' adDouble    MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble  MM_editCmd2.Execute	MM_editCmd2.ActiveConnection.Close	' append the query string to the redirect URL	Dim MM_editRedirectUrl2	MM_editRedirectUrl2 = "newsEditHome.asp"	If (Request.QueryString <> "") Then	  If (InStr(1, MM_editRedirectUrl2, "?", vbTextCompare) = 0) Then		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "?" & Request.QueryString	  Else		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "&" & Request.QueryString	  End If	End If	Response.Redirect(MM_editRedirectUrl2)  End IfEnd If%>

One more thing, you can see I have two recordSets on the page (rsMessageIndex and rsMessageChoisi). I don't know why I couldn't use just one. I kept having the following error if I used the main recordSet (rsMessageIndex):ADODB.Field</FONT> error '800a0bcd' Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.As I said, I'm a newbie at ASP. I worked with Dreamweaver which did almost all the code for me. Since I know ActionScipt, I canwork my way through code a little bit.Thanks for your time

Link to comment
Share on other sites

You don't give your radio buttons a value, so you can't tell which one was clicked on. You need to give all radio buttons the same name and different values, then when you check in request.form it should have the value for the button that you selected.<input type="radio" name="radioChoisi" value="1"><input type="radio" name="radioChoisi" value="2"><input type="radio" name="radioChoisi" value="3">The error message (either EOF or BOF is true) generally means that the recordset doesn't have any results. You can check for that before you try to use it, if you get your results from the database and then check if recordsetobject.EOF is true, then that means no records were returned (EOF = end of file, BOF = beginning of file). You'll have to check down on line 528 to see what it's doing there.

Link to comment
Share on other sites

I changed the value to :rsMessageIndex.Fields.Item("intMessageID").Value. It is the unique key of my message Table. but the form still doesn't apply the changes to the message table. The messages that were checked are still cheked, and thoses who weren't still are not.Is it okay if the value numbers are not 1,2,3,... but 13, 16, 17,....? And they might not stay these numbers as the administrator can delete and create new entries in the database.here's the updated code:

<form id="frmMessageChoisi" name="frmMessageChoisi" method="POST" action="<%=MM_editAction%>"><table>   <tr>	<th>Date</th>	<th>Titre</th>	<th>Message</th>	<th>Selectionné</th>   </tr>  <% While ((Repeat1__numRows <> 0) AND (NOT rsMessageIndex.EOF)) %>	<tr>	 <td><a href="newsEditDetail.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "id=" & rsMessageIndex.Fields.Item("intMessageID").Value %>"><%=(rsMessageIndex.Fields.Item("dtePostDate").Value)%></a></td>	 <td><%=(rsMessageIndex.Fields.Item("txtMessageTitle").Value)%></td>	 <td><%=(rsMessageIndex.Fields.Item("memPostMessage").Value)%></td>	 <td>	  <div align="center">	   <input <%If (CStr((rsMessageIndex.Fields.Item("bitMessageChoisi").Value)) = CStr("True")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="radioChoisi" type="radio" value="<%= rsMessageIndex.Fields.Item("intMessageID").Value%>" onchange="submit()"/>	  </div>	 </td>	</tr>  <%    Response.write("radios" & rsMessageIndex.Fields.Item("intMessageID").Value)   	Repeat1__index=Repeat1__index+1	Repeat1__numRows=Repeat1__numRows-1	rsMessageIndex.MoveNext()    Wend  %> </table><input type="hidden" name="MM_update" value="frmMessageChoisi" /><input type="hidden" name="MM_recordId" value="<%=(rsMessageChoisi.Fields.Item("intMessageID").Value)%>" /> </form>

Link to comment
Share on other sites

Yeah that's right, you've got the right idea. The code seems to have gotten messy though. But yeah, you just want to print the ID so that you know which row to update in the database. But I think you have your parameters in the wrong order. Your query is this:"UPDATE messages SET bitMessageChoisi = ? WHERE intMessageID = ?"But your first parameter is the ID and the second is the message. Switch those two addParameter statements so that it adds the message first, then the ID.

Link to comment
Share on other sites

Should I write it like this : "UPDATE messages SET intMessageID = ? WHERE bitMessageChoisi = ?"or like this:"UPDATE messages WHERE bitMessageChoisi = ? SET intMessageID = ?"?The first option gives me that error:

Microsoft JET Database Engine error '80040e21' Cannot update 'intMessageID'; field not updateable. /opiaPlayground/soccerBoreal/newsEditHome.asp, line 89

and the second option gives me :

Microsoft JET Database Engine error '80040e14' Syntax error in UPDATE statement. /opiaPlayground/soccerBoreal/newsEditHome.asp, line 89

Would it be easier if I just sent the whole code :) ?

Link to comment
Share on other sites

anyways, here's the whole page....

<%' *** Restrict Access To Page: Grant or deny access to this pageMM_authorizedUsers="1,2"MM_authFailedURL="loginNews.asp"MM_grantAccess=falseIf Session("MM_Username") <> "" Then  If (false Or CStr(Session("MM_UserAuthorization"))="") Or _		 (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then	MM_grantAccess = true  End IfEnd IfIf Not MM_grantAccess Then  MM_qsChar = "?"  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"  MM_referrer = Request.ServerVariables("URL")  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)  Response.Redirect(MM_authFailedURL)End If%><!--#include file="Connections/connUsers.asp" --><%Dim MM_editActionMM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))If (Request.QueryString <> "") Then  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)End If' boolean to abort record editDim MM_abortEditMM_abortEdit = false%><%' IIf implementationFunction MM_IIf(condition, ifTrue, ifFalse)  If condition = "" Then	MM_IIf = ifFalse  Else	MM_IIf = ifTrue  End IfEnd Function%><%If (CStr(Request("MM_insert")) = "formulaire de messages") Then  If (Not MM_abortEdit) Then	' execute the insert	Dim MM_editCmd	Set MM_editCmd = Server.CreateObject ("ADODB.Command")	MM_editCmd.ActiveConnection = MM_connUsers_STRING	MM_editCmd.CommandText = "INSERT INTO messages (txtMessageTitle, memPostMessage, dtePostDate, intPostBy) VALUES (?, ?, ?, ?)" 	MM_editCmd.Prepared = true	MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("txtMessageTitle")) ' adVarWChar	MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 203, 1, 536870910, Request.Form("memPostMessage")) ' adLongVarWChar	MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 135, 1, -1, MM_IIF(Request.Form("dtePostDate"), Request.Form("dtePostDate"), null)) ' adDBTimeStamp	MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("intPostBy"), Request.Form("intPostBy"), null)) ' adDouble	MM_editCmd.Execute	MM_editCmd.ActiveConnection.Close	' append the query string to the redirect URL	Dim MM_editRedirectUrl	MM_editRedirectUrl = "newsEditHome.asp"	If (Request.QueryString <> "") Then	  If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then		MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString	  Else		MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString	  End If	End If	Response.Redirect(MM_editRedirectUrl)  End IfEnd If%><%If (CStr(Request("MM_update")) = "frmMessageChoisi") Then  If (Not MM_abortEdit) Then	' execute the update	Dim MM_editCmd2	Set MM_editCmd2 = Server.CreateObject ("ADODB.Command")	MM_editCmd2.ActiveConnection = MM_connUsers_STRING	MM_editCmd2.CommandText = "UPDATE messages SET bitMessageChoisi = ? WHERE intMessageID = ?" 	MM_editCmd2.Prepared = true  MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("radioChoisi"), "-1", "0")) ' adDouble    MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble  MM_editCmd2.Execute	MM_editCmd2.ActiveConnection.Close	' append the query string to the redirect URL	Dim MM_editRedirectUrl2	MM_editRedirectUrl2 = "newsEditHome.asp"	If (Request.QueryString <> "") Then	  If (InStr(1, MM_editRedirectUrl2, "?", vbTextCompare) = 0) Then		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "?" & Request.QueryString	  Else		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "&" & Request.QueryString	  End If	End If	Response.Redirect(MM_editRedirectUrl2)  End IfEnd If%><%Dim rsMessageIndexDim rsMessageIndex_cmdDim rsMessageIndex_numRowsSet rsMessageIndex_cmd = Server.CreateObject ("ADODB.Command")rsMessageIndex_cmd.ActiveConnection = MM_connUsers_STRINGrsMessageIndex_cmd.CommandText = "SELECT bitMessageChoisi, dtePostDate, intMessageID, memPostMessage, txtMessageTitle FROM messages ORDER BY dtePostDate ASC" rsMessageIndex_cmd.Prepared = trueSet rsMessageIndex = rsMessageIndex_cmd.ExecutersMessageIndex_numRows = 0%><%Dim rsMessageChoisiDim rsMessageChoisi_cmdDim rsMessageChoisi_numRowsSet rsMessageChoisi_cmd = Server.CreateObject ("ADODB.Command")rsMessageChoisi_cmd.ActiveConnection = MM_connUsers_STRINGrsMessageChoisi_cmd.CommandText = "SELECT bitMessageChoisi, intMessageID FROM messages" rsMessageChoisi_cmd.Prepared = trueSet rsMessageChoisi = rsMessageChoisi_cmd.ExecutersMessageChoisi_numRows = 0%><%Dim Repeat1__numRowsDim Repeat1__indexRepeat1__numRows = -1Repeat1__index = 0rsMessageIndex_numRows = rsMessageIndex_numRows + Repeat1__numRows%><%'  *** Recordset Stats, Move To Record, and Go To Record: declare stats variablesDim rsMessageIndex_totalDim rsMessageIndex_firstDim rsMessageIndex_last' set the record countrsMessageIndex_total = rsMessageIndex.RecordCount' set the number of rows displayed on this pageIf (rsMessageIndex_numRows < 0) Then  rsMessageIndex_numRows = rsMessageIndex_totalElseif (rsMessageIndex_numRows = 0) Then  rsMessageIndex_numRows = 1End If' set the first and last displayed recordrsMessageIndex_first = 1rsMessageIndex_last  = rsMessageIndex_first + rsMessageIndex_numRows - 1' if we have the correct record count, check the other statsIf (rsMessageIndex_total <> -1) Then  If (rsMessageIndex_first > rsMessageIndex_total) Then	rsMessageIndex_first = rsMessageIndex_total  End If  If (rsMessageIndex_last > rsMessageIndex_total) Then	rsMessageIndex_last = rsMessageIndex_total  End If  If (rsMessageIndex_numRows > rsMessageIndex_total) Then	rsMessageIndex_numRows = rsMessageIndex_total  End IfEnd If%><%' *** Recordset Stats: if we don't know the record count, manually count themIf (rsMessageIndex_total = -1) Then  ' count the total records by iterating through the recordset  rsMessageIndex_total=0  While (Not rsMessageIndex.EOF)	rsMessageIndex_total = rsMessageIndex_total + 1	rsMessageIndex.MoveNext  Wend  ' reset the cursor to the beginning  If (rsMessageIndex.CursorType > 0) Then	rsMessageIndex.MoveFirst  Else	rsMessageIndex.Requery  End If  ' set the number of rows displayed on this page  If (rsMessageIndex_numRows < 0 Or rsMessageIndex_numRows > rsMessageIndex_total) Then	rsMessageIndex_numRows = rsMessageIndex_total  End If  ' set the first and last displayed record  rsMessageIndex_first = 1  rsMessageIndex_last = rsMessageIndex_first + rsMessageIndex_numRows - 1    If (rsMessageIndex_first > rsMessageIndex_total) Then	rsMessageIndex_first = rsMessageIndex_total  End If  If (rsMessageIndex_last > rsMessageIndex_total) Then	rsMessageIndex_last = rsMessageIndex_total  End IfEnd If%><%Dim MM_paramName %><%' *** Move To Record and Go To Record: declare variablesDim MM_rsDim MM_rsCountDim MM_sizeDim MM_uniqueColDim MM_offsetDim MM_atTotalDim MM_paramIsDefinedDim MM_paramDim MM_indexSet MM_rs	= rsMessageIndexMM_rsCount   = rsMessageIndex_totalMM_size	  = rsMessageIndex_numRowsMM_uniqueCol = ""MM_paramName = ""MM_offset = 0MM_atTotal = falseMM_paramIsDefined = falseIf (MM_paramName <> "") Then  MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")End If%><%' *** Move To Record: handle 'index' or 'offset' parameterif (Not MM_paramIsDefined And MM_rsCount <> 0) then  ' use index parameter if defined, otherwise use offset parameter  MM_param = Request.QueryString("index")  If (MM_param = "") Then	MM_param = Request.QueryString("offset")  End If  If (MM_param <> "") Then	MM_offset = Int(MM_param)  End If  ' if we have a record count, check if we are past the end of the recordset  If (MM_rsCount <> -1) Then	If (MM_offset >= MM_rsCount Or MM_offset = -1) Then  ' past end or move last	  If ((MM_rsCount Mod MM_size) > 0) Then		 ' last page not a full repeat region		MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)	  Else		MM_offset = MM_rsCount - MM_size	  End If	End If  End If  ' move the cursor to the selected record  MM_index = 0  While ((Not MM_rs.EOF) And (MM_index < MM_offset Or MM_offset = -1))	MM_rs.MoveNext	MM_index = MM_index + 1  Wend  If (MM_rs.EOF) Then 	MM_offset = MM_index  ' set MM_offset to the last possible record  End IfEnd If%><%' *** Move To Record: if we dont know the record count, check the display rangeIf (MM_rsCount = -1) Then  ' walk to the end of the display range for this page  MM_index = MM_offset  While (Not MM_rs.EOF And (MM_size < 0 Or MM_index < MM_offset + MM_size))	MM_rs.MoveNext	MM_index = MM_index + 1  Wend  ' if we walked off the end of the recordset, set MM_rsCount and MM_size  If (MM_rs.EOF) Then	MM_rsCount = MM_index	If (MM_size < 0 Or MM_size > MM_rsCount) Then	  MM_size = MM_rsCount	End If  End If  ' if we walked off the end, set the offset based on page size  If (MM_rs.EOF And Not MM_paramIsDefined) Then	If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then	  If ((MM_rsCount Mod MM_size) > 0) Then		MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)	  Else		MM_offset = MM_rsCount - MM_size	  End If	End If  End If  ' reset the cursor to the beginning  If (MM_rs.CursorType > 0) Then	MM_rs.MoveFirst  Else	MM_rs.Requery  End If  ' move the cursor to the selected record  MM_index = 0  While (Not MM_rs.EOF And MM_index < MM_offset)	MM_rs.MoveNext	MM_index = MM_index + 1  WendEnd If%><%' *** Move To Record: update recordset stats' set the first and last displayed recordrsMessageIndex_first = MM_offset + 1rsMessageIndex_last  = MM_offset + MM_sizeIf (MM_rsCount <> -1) Then  If (rsMessageIndex_first > MM_rsCount) Then	rsMessageIndex_first = MM_rsCount  End If  If (rsMessageIndex_last > MM_rsCount) Then	rsMessageIndex_last = MM_rsCount  End IfEnd If' set the boolean used by hide region to check if we are on the last recordMM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)%><%' *** Go To Record and Move To Record: create strings for maintaining URL and Form parametersDim MM_keepNoneDim MM_keepURLDim MM_keepFormDim MM_keepBothDim MM_removeListDim MM_itemDim MM_nextItem' create the list of parameters which should not be maintainedMM_removeList = "&index="If (MM_paramName <> "") Then  MM_removeList = MM_removeList & "&" & MM_paramName & "="End IfMM_keepURL=""MM_keepForm=""MM_keepBoth=""MM_keepNone=""' add the URL parameters to the MM_keepURL stringFor Each MM_item In Request.QueryString  MM_nextItem = "&" & MM_item & "="  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then	MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))  End IfNext' add the Form variables to the MM_keepForm stringFor Each MM_item In Request.Form  MM_nextItem = "&" & MM_item & "="  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then	MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))  End IfNext' create the Form + URL string and remove the intial '&' from each of the stringsMM_keepBoth = MM_keepURL & MM_keepFormIf (MM_keepBoth <> "") Then   MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)End IfIf (MM_keepURL <> "")  Then  MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)End IfIf (MM_keepForm <> "") Then  MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)End If' a utility function used for adding additional parameters to these stringsFunction MM_joinChar(firstItem)  If (firstItem <> "") Then	MM_joinChar = "&"  Else	MM_joinChar = ""  End IfEnd Function%><%' *** Move To Record: set the strings for the first, last, next, and previous linksDim MM_keepMoveDim MM_moveParamDim MM_moveFirstDim MM_moveLastDim MM_moveNextDim MM_movePrevDim MM_urlStrDim MM_paramListDim MM_paramIndexDim MM_nextParamMM_keepMove = MM_keepBothMM_moveParam = "index"' if the page has a repeated region, remove 'offset' from the maintained parametersIf (MM_size > 1) Then  MM_moveParam = "offset"  If (MM_keepMove <> "") Then	MM_paramList = Split(MM_keepMove, "&")	MM_keepMove = ""	For MM_paramIndex = 0 To UBound(MM_paramList)	  MM_nextParam = Left(MM_paramList(MM_paramIndex), InStr(MM_paramList(MM_paramIndex),"=") - 1)	  If (StrComp(MM_nextParam,MM_moveParam,1) <> 0) Then		MM_keepMove = MM_keepMove & "&" & MM_paramList(MM_paramIndex)	  End If	Next	If (MM_keepMove <> "") Then	  MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)	End If  End IfEnd If' set the strings for the move to linksIf (MM_keepMove <> "") Then   MM_keepMove = Server.HTMLEncode(MM_keepMove) & "&"End IfMM_urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="MM_moveFirst = MM_urlStr & "0"MM_moveLast  = MM_urlStr & "-1"MM_moveNext  = MM_urlStr & CStr(MM_offset + MM_size)If (MM_offset - MM_size < 0) Then  MM_movePrev = MM_urlStr & "0"Else  MM_movePrev = MM_urlStr & CStr(MM_offset - MM_size)End If%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]"><html xmlns="[url="http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml[/url]"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Modification du message de nouvelles</title> <link rel="stylesheet" type="text/css" href="CSS/loginNews.css"></head><body> <h1>Page de création du message d'accueil</h1> <p>Bonjour <%= Session("MM_Username") %></p> <p><a href="newsEditLogOut.asp">terminer les modifications</a></p> <p>Création de nouveaux messages</p> <% If rsMessageIndex.EOF And rsMessageIndex.BOF Then %>  <p>Aucun message enregistré...</p>  <% End If ' end rsMessageIndex.EOF And rsMessageIndex.BOF %>  <form action="<%=MM_editAction%>" method="POST" name="formulaire de messages" id="formulaire de messages">   <table>   <tr valign="baseline">	 <td nowrap="nowrap" align="right">Titre:</td>	 <td><input type="text" name="txtMessageTitle" value="" size="50" />	 </td>	</tr>	<tr>	 <td nowrap="nowrap" align="right" valign="top">Message:</td>	 <td valign="baseline"><textarea name="memPostMessage" cols="50" rows="5"></textarea>	 </td>	</tr>	<tr valign="baseline">	 <td nowrap="nowrap" align="right">Date:</td>	 <td><input type="text" name="dtePostDate" value="<%=now() %>" size="32" />	 </td>	</tr>	<tr valign="baseline">	 <td nowrap="nowrap" align="right"> </td>	 <td><input name="enregistrer" type="submit" id="enregistrer" value="Enregistrer le message" />	 </td>	</tr>   </table>   <input type="hidden" name="intPostBy" value="<%= Session("MM_UserID") %>" />   <input type="hidden" name="MM_insert" value="formulaire de messages" />  </form>     <p> </p> Liste des messages enregistrés. Cliquez sur la date pour les modifier.<br /><br /><form id="frmMessageChoisi" name="frmMessageChoisi" method="POST" action="<%=MM_editAction%>"><table>   <tr>	<th>Date</th>	<th>Titre</th>	<th>Message</th>	<th>Selectionné</th>   </tr>  <% While ((Repeat1__numRows <> 0) AND (NOT rsMessageIndex.EOF)) %>	<tr>	 <td><a href="newsEditDetail.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "id=" & rsMessageIndex.Fields.Item("intMessageID").Value %>"><%=(rsMessageIndex.Fields.Item("dtePostDate").Value)%></a></td>	 <td><%=(rsMessageIndex.Fields.Item("txtMessageTitle").Value)%></td>	 <td><%=(rsMessageIndex.Fields.Item("memPostMessage").Value)%></td>	 <td>	  <div align="center">	   <input <%If (CStr((rsMessageIndex.Fields.Item("bitMessageChoisi").Value)) = CStr("True")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="radioChoisi" type="radio" value="<%= rsMessageIndex.Fields.Item("intMessageID").Value%>" onchange="submit()"/>	  </div>	 </td>	</tr>  <%    Response.write("radios" & rsMessageIndex.Fields.Item("intMessageID").Value)   	Repeat1__index=Repeat1__index+1	Repeat1__numRows=Repeat1__numRows-1	rsMessageIndex.MoveNext()    Wend  %> </table><input type="hidden" name="MM_update" value="frmMessageChoisi" /><input type="hidden" name="MM_recordId" value="<%=(rsMessageChoisi.Fields.Item("intMessageID").Value)%>" /> </form> </body></html><%rsMessageIndex.Close()Set rsMessageIndex = Nothing%><%rsMessageChoisi.Close()Set rsMessageChoisi = Nothing%>

Link to comment
Share on other sites

Should I write it like this : "UPDATE messages SET intMessageID = ? WHERE bitMessageChoisi = ?"or like this:"UPDATE messages WHERE bitMessageChoisi = ? SET intMessageID = ?"
Neither, leave the query like it was, that wasn't what I was talking about. There are 2 lines after the query that add parameters. Those lines need to be switched. You need to add the parameters in the same order that they show up in the query.
Link to comment
Share on other sites

Neither, leave the query like it was, that wasn't what I was talking about. There are 2 lines after the query that add parameters. Those lines need to be switched. You need to add the parameters in the same order that they show up in the query.
I tried that, but no change.I forgot to mention that I used 2 recordsets because when I used the main one (reMessageIndex), I had the following error message:
ADODB.Field</FONT> error '800a0bcd' Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. /opiaPlayground/soccerBoreal/newsEditHome.asp, line 526
and the line 526 refers to :
<input type="hidden" name="MM_recordId" value="<%=(rsMessageIndex.Fields.Item("intMessageID").Value)%>" />

At the end of the Whole code Page I posted previously, you can see that the value is rsMessageChoisi.Fields... instead of rsMessageIndex.Fields... It was an attempt at avoiding an error, not so clever of me.......I tried some Response.write to verify if rsMessageIndex.Fields.Item("intMessageID").Value could be called from there. I realized I could not access it once I put the Response.write after the rsMessageIndex.MoveNext() in the loop section at the bottom of the Whole script page:

<%    Response.write("radios" & rsMessageIndex.Fields.Item("intMessageID").Value)   	Repeat1__index=Repeat1__index+1	Repeat1__numRows=Repeat1__numRows-1	rsMessageIndex.MoveNext()    Wend  %>

Do you have an Idea what it could be?

Link to comment
Share on other sites

So where are you at this point, what are you trying to solve?
Sorry, maybe I should start from scratch. It will be easier that way. :) here's the problematic page : http://web2.uqat.ca/opiaPlayground/soccerB...ewsEditHome.asplogin:testpassword:test
  • I made a dynamic table which holds data from an Access database.
  • I then added a radioButton at the end of each entry of the dynamic table.
  • I was able to reference the radioButtons to the checkbox entry of my database so we can see which entry is selected.
  • I selected only one checkbox in Access so I could make use of the checkboxes as a radiobutton group in ASP.
  • I embedded the dynamic table in a form so when I choose a radio button (onchange), the form refreshes the page.

Here is the code :

<form id="frmMessageChoisi" name="frmMessageChoisi" method="POST" action="<%=MM_editAction%>"><table>   <tr>	<th>Date</th>	<th>Titre</th>	<th>Message</th>	<th>Selectionné</th>   </tr>  <% While ((Repeat1__numRows <> 0) AND (NOT rsMessageIndex.EOF)) %>	<tr>	 <td><a href="newsEditDetail.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "id=" & rsMessageIndex.Fields.Item("intMessageID").Value %>"><%=(rsMessageIndex.Fields.Item("dtePostDate").Value)%></a></td>	 <td><%=(rsMessageIndex.Fields.Item("txtMessageTitle").Value)%></td>	 <td><%=(rsMessageIndex.Fields.Item("memPostMessage").Value)%></td>	 <td>	  <div align="center">	   <input <%If (CStr((rsMessageIndex.Fields.Item("bitMessageChoisi").Value)) = CStr("True")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="radioChoisi" type="radio" value="<%= rsMessageIndex.Fields.Item("intMessageID").Value%>" onchange="submit()"/>	  </div>	 </td>	</tr>  <%	 	Repeat1__index=Repeat1__index+1	Repeat1__numRows=Repeat1__numRows-1	rsMessageIndex.MoveNext()    Wend  %> </table><input type="hidden" name="MM_update" value="frmMessageChoisi" /><input type="hidden" name="MM_recordId" value="<%=(rsMessageIndex.Fields.Item("intMessageID").Value)%>" /> </form>

See, I have a while command processing all the elements of my dynamic table. So everything appears as it should and that's fine.My problem is that i get that error about the recordset:

ADODB.Field</FONT> error '800a0bcd' Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. /opiaPlayground/soccerBoreal/newsEditHome.asp, line 526

here's line 526:

<input type="hidden" name="MM_recordId" value="<%=(rsMessageIndex.Fields.Item("intMessageID").Value)%>" />

......as if the recordset was no longer interpreted below the rsMessageIndex.MoveNext() line.Then, when you try to select a different radioButton (then click elsewhere), you get another error:

ADODB.Command error '800a0d5d'Application uses a value of the wrong type for the current operation./opiaPlayground/soccerBoreal/newsEditHome.asp, line 87

here's line 87:

MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null))

What can I do to submit my radioButton choices, knowing that ASP communicates with an Access database, and that the radioButtons are in Yes/No checkboxes in Access?

Link to comment
Share on other sites

The EOF error means that the last movenext moved the recordset to the end, there aren't any more records. What are you trying to put in this:<input type="hidden" name="MM_recordId" value="<%=(rsMessageIndex.Fields.Item("intMessageID").Value)%>" />What record ID are you trying to put there?I'm not sure what the MM_IIF function is trying to do, but replace line 87 with this:

MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param2", 3, 1, 0, CInt(Request.Form("MM_recordId")))

Link to comment
Share on other sites

The EOF error means that the last movenext moved the recordset to the end, there aren't any more records. What are you trying to put in this:<input type="hidden" name="MM_recordId" value="<%=(rsMessageIndex.Fields.Item("intMessageID").Value)%>" />What record ID are you trying to put there?I'm not sure what the MM_IIF function is trying to do, but replace line 87 with this:
MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param2", 3, 1, 0, CInt(Request.Form("MM_recordId")))

I replaced the line 87 and IE gives me that error message:
Microsoft VBScript runtime error '800a000d' Type mismatch: 'CInt' /opiaPlayground/soccerBoreal/newsEditHome.asp, line 87
The record ID i'm trying to put there is the unique key from my database, which corresponds to the entry number of each checkbox in my database:I want intMessageID be to the value of each radioButton on my web page. Then I want my form(frmMessageChoisi) to update my database, updating all the checkboxes at once, leaving the newly selectedentry(bitMessageChoisi) to TRUE.Is it possible to do that ?
Link to comment
Share on other sites

I want intMessageID be to the value of each radioButton on my web page.
OK, but the input tag causing the EOF error is not inside the loop where you loop through the database results. You don't even need that tag though. All you need is a name and a value on each radio button. The value should be the record ID for that record (which I think it is). The ADODB.command objects and things I think are only confusing things. If you give the radio buttons the values of the ID that you want selected, then you can update the database like this:
Set dbcon = Server.CreateObject("ADODB.RecordSet")dbcon.ActiveConnection = MM_connUsers_STRINGdbcon.open("UPDATE Messages set bitMessageChoisi = 0")dbcon.open("UPDATE Messages set bitMessageChoisi = 1 WHERE intMessageId = " & Request.Form("radioChoisi"))

Link to comment
Share on other sites

OK, but the input tag causing the EOF error is not inside the loop where you loop through the database results. You don't even need that tag though.
these lines:
<input type="hidden" name="[b]MM_update[/b]" value="frmMessageChoisi" /><input type="hidden" name="[b]MM_recordId[/b]" value="<%=(rsMessageIndex.Fields.Item("intMessageID").Value)%>" />

are emmbeded at the end of my form tag. I think they relate to the following functions:here is MM_update (from the first line):

If (CStr(Request("[b]MM_update[/b]")) = "frmMessageChoisi") Then  If (Not MM_abortEdit) Then	' execute the update	Dim MM_editCmd2	Set MM_editCmd2 = Server.CreateObject ("ADODB.Command")	MM_editCmd2.ActiveConnection = MM_connUsers_STRING	MM_editCmd2.CommandText = "UPDATE messages SET bitMessageChoisi = ? WHERE intMessageID = ?" 	MM_editCmd2.Prepared = true  MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("radioChoisi"), "-1", "0")) ' adDouble   MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("[b]MM_recordId[/b]"), Request.Form("MM_recordId"), null)) MM_editCmd2.Execute	MM_editCmd2.ActiveConnection.Close	' append the query string to the redirect URL	Dim MM_editRedirectUrl2	MM_editRedirectUrl2 = "newsEditHome.asp"	If (Request.QueryString <> "") Then	  If (InStr(1, MM_editRedirectUrl2, "?", vbTextCompare) = 0) Then		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "?" & Request.QueryString	  Else		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "&" & Request.QueryString	  End If	End If	Response.Redirect(MM_editRedirectUrl2)  End IfEnd If

and the MM_IIF:

Function MM_IIf(condition, ifTrue, ifFalse)  If condition = "" Then	MM_IIf = ifFalse  Else	MM_IIf = ifTrue  End IfEnd Function

I think the radioButton might work on the page, but I also think they do not communucate correctly with the database when I submit.I my reasoning is right, the functionnality of the form should turn the newly selected value tu true. But will it turn the old "true" value to false on the database?

Link to comment
Share on other sites

The code that I posted above will turn all values false and then the one you selected true. The first input tag is fine, it doesn't have anything from the database, the second tag can't be there because by the time it gets written out the database records are already exhausted, but it's trying to use one of them. The code you have will probably work if you delete that tag and change the names of the radio buttons to "MM_recordId".

Link to comment
Share on other sites

The code that I posted above will turn all values false and then the one you selected true. The first input tag is fine, it doesn't have anything from the database, the second tag can't be there because by the time it gets written out the database records are already exhausted, but it's trying to use one of them. The code you have will probably work if you delete that tag and change the names of the radio buttons to "MM_recordId".
Okay, by the way, thanks for your patience :) I removed the problematic tag.I changed the name of the buttonGroup radioChoisi:
<input <%If (CStr((rsMessageIndex.Fields.Item("bitMessageChoisi").Value)) = CStr("True")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="radioChoisi" type="radio" value="<%= rsMessageIndex.Fields.Item("intMessageID").Value%>" onchange="submit()"/>

to MM_recordID:

<input <%If (CStr((rsMessageIndex.Fields.Item("bitMessageChoisi").Value)) = CStr("True")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="MM_recordID" type="radio" value="<%= rsMessageIndex.Fields.Item("intMessageID").Value%>" onchange="submit()"/>

and here's how I adapted the command lines you gave me:

If (CStr(Request("MM_update")) = "frmMessageChoisi") Then  If (Not MM_abortEdit) Then	' execute the update	Dim MM_editCmd2	Set MM_editCmd2 = Server.CreateObject ("ADODB.Command")	MM_editCmd2.ActiveConnection = MM_connUsers_STRING	MM_editCmd2.CommandText = "UPDATE messages SET bitMessageChoisi = ? WHERE intMessageID = ?" 	MM_editCmd2.Prepared = true  MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("radioChoisi"), "-1", "0")) ' adDouble   MM_editCmd2.Parameters.Append MM_editCmd2.CreateParameter("param2", 3, 1, 0, CInt(Request.Form("MM_recordId"))) MM_editCmd2.open("UPDATE Messages set bitMessageChoisi = 0") MM_editCmd2.open("UPDATE Messages set bitMessageChoisi = 1 WHERE intMessageId = " & Request.Form("radioChoisi")) MM_editCmd2.Execute	MM_editCmd2.ActiveConnection.Close	' append the query string to the redirect URL	Dim MM_editRedirectUrl2	MM_editRedirectUrl2 = "newsEditHome.asp"	If (Request.QueryString <> "") Then	  If (InStr(1, MM_editRedirectUrl2, "?", vbTextCompare) = 0) Then		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "?" & Request.QueryString	  Else		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "&" & Request.QueryString	  End If	End If	Response.Redirect(MM_editRedirectUrl2)  End IfEnd If

when I publish the page, everything is fine until I submit the form.It then gives me an error message:

Microsoft VBScript runtime error '800a01b6' Object doesn't support this property or method: 'open' /opiaPlayground/soccerBoreal/newsEditHome.asp, line 88
did I put the line in the wrong place?
Link to comment
Share on other sites

You're using an ADODB command object instead of a recordset object. This should work:

If (CStr(Request("MM_update")) = "frmMessageChoisi") Then  If (Not MM_abortEdit) Then	' execute the update	Dim MM_editCmd2	Set MM_editCmd2 = Server.CreateObject ("ADODB.RecordSet")	MM_editCmd2.ActiveConnection = MM_connUsers_STRING	MM_editCmd2.open("UPDATE Messages set bitMessageChoisi = 0")	MM_editCmd2.open("UPDATE Messages set bitMessageChoisi = 1 WHERE intMessageId = " & Request.Form("MM_recordId"))	' append the query string to the redirect URL	Dim MM_editRedirectUrl2	MM_editRedirectUrl2 = "newsEditHome.asp"	If (Request.QueryString <> "") Then	  If (InStr(1, MM_editRedirectUrl2, "?", vbTextCompare) = 0) Then		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "?" & Request.QueryString	  Else		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "&" & Request.QueryString	  End If	End If	Response.Redirect(MM_editRedirectUrl2)  End IfEnd If

Link to comment
Share on other sites

You're using an ADODB command object instead of a recordset object. This should work:
If (CStr(Request("MM_update")) = "frmMessageChoisi") Then  If (Not MM_abortEdit) Then	' execute the update	Dim MM_editCmd2	Set MM_editCmd2 = Server.CreateObject ("ADODB.RecordSet")	MM_editCmd2.ActiveConnection = MM_connUsers_STRING	MM_editCmd2.open("UPDATE Messages set bitMessageChoisi = 0")	MM_editCmd2.open("UPDATE Messages set bitMessageChoisi = 1 WHERE intMessageId = " & Request.Form("MM_recordId"))	' append the query string to the redirect URL	Dim MM_editRedirectUrl2	MM_editRedirectUrl2 = "newsEditHome.asp"	If (Request.QueryString <> "") Then	  If (InStr(1, MM_editRedirectUrl2, "?", vbTextCompare) = 0) Then		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "?" & Request.QueryString	  Else		MM_editRedirectUrl2 = MM_editRedirectUrl2 & "&" & Request.QueryString	  End If	End If	Response.Redirect(MM_editRedirectUrl2)  End IfEnd If

would it be possible to update an XML file with the content of the new selection directly from that code?I only have one node in the XML file. This node would hold the selected message.example:<message>this is the selected message</message>every time I would select a different radiobutton, the message would be replaced by the new selection.I don't know where to start
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...