borrar varios registros seleccionados con un checkBox

daniel ivan
23 de Febrero del 2006
Holaaa!!
Tengo un problema que ya no se como voy a resolver. Resulta que simplemente quiero eliminar registros de una base de datos. Muestros los elementos de la misma en una tabla y por cada registro tengo un checkBox. Al final de la tabla tengo un boton Eliminar, que al pulsar se supone que tiene que elimininar los registros seleccionados. Nombro cada checkBox con el "id" correspondiente a su registro, pero no se como hacer para borrarlos. Este es el codigo del primer fichero, donde esta el formulario:
<!--Conexión a la base de datos y a la tabla Actividades -->
<% dim Ob_Conn, Ob_RS %>

<% Set Ob_Conn = Server.CreateObject("ADODB.Connection")
'Ob_Conn.Open "bdactividades"
'Se conecta a la base de datos local. Va al directorio donde se encuentra el archivo ASP.
Ob_Conn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("baseDeDatosCamping.mdb"))
Set Ob_RS=Ob_Conn.Execute("SELECT * FROM Actividades")
%>
<TABLE BORDER=1>
<TR>
<TD></TD> <!--En esta columna ira un checkbox por cada registro-->
<TD> HORA DE INICIO </TD>
<TD> HORA DE FIN </TD>
<TD> ACTIVIDAD </TD>
<TD> LUGAR </TD>
<TD> </TD>
<%dim i
dim nombreBotonEliminar(20)
i=0%>
<!--En esta columna irá un hiperenlace hacia una pagina de modificacion del registro correspondiente-->
<form name="formCheckBoxEliminarActividad" method="get" action="paginaEliminarActividades.asp">
<% DO UNTIL Ob_RS.Eof %>
<TR>
<% numReg=Ob_RS("Id") %>

<!--Por cada elemento de la tablaActividades, se incluye un checkbox cuyo nombre será el id q tiene
su registro correspondiente en la tabla-->

<TD>
<% 'Esta variable contendrá el nombre del botón eliminar correspondiente a cada registro, que será
' el id de ese registro. Asi al llamar a la pagina "paginaBorrarActividades.asp", utiliza
' esta variable session para acceder al nombre del registro que se desea borrar. La variable session
' desaparece a los 20 minutos de inactividad.

i=i+1 %>


<input type="checkBox" name="<%=Ob_RS("Id")%>" value="" >

</TD>
<TD> <%=Ob_RS("Inicio")%> </TD>
<TD> <%=Ob_RS("Fin")%> </TD>
<TD> <%=Ob_RS("Actividad")%> </TD>
<TD> <%=Ob_RS("Lugar")%> </TD>
<TD> <A REF="" target="_blank"> Modificar </A> </TD>
<%Ob_RS.MoveNext
LOOP
Ob_RS.Close
Ob_Conn.Close %>
</TABLE>

<input type="submit" name="botonEliminar" value="Eliminar">
</form>

Y este es el codigo del fichero a donde mando el formulario:

% SUB bajaActividad()
<!--**Se conecta a la base de datos-->
Set Ob_Conn=Server.CreateObject("ADODB.Connection")
'Ob_Conn.Open "bdactividades"
'Se conecta a la base de datos local
Ob_Conn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("baseDeDatosCamping.mdb"))
Set Ob_RS=Server.CreateObject("ADODB.RecordSet")
Ob_RS.Open "Actividades", Ob_Conn, AdOpenStatic, AdCmdTable
Ob_RS.MoveFirst

FOR EACH var IN Request.QueryString %>
<!--Si el checkBox correspondiente a este registro, está seleccionado, se borra el registro-->
<% IF isnumeric(var) THEN
response.write "Id borrado" & Ob_RS("Id") %> <BR> <%
Ob_RS.Source="Delete * from Ob_RS where[id]=" & var
Ob_RS.Open
END IF
NEXT
Ob_RS.Close
Ob_Conn.Close
'Response.Redirect ("paginaIntroduccionActividadesDiarias.asp") 'Abro la pagina de introduccion de actividades diarias, para que se muestren los cambios

END SUB %> <!--Fin del procedimiento

Intento borrar los datos con el delete, pero creo que cometo algun error con el metodo Source, que no tengo muy claro de como funciona.

Agradeceria mucho que alguien me dijera como se hace, porque llevo ya 5 dias con este problemilla.
Muchas gracias, gracias, gracias.

Carlos
23 de Febrero del 2006
Estimado Daniel:

Lei muy por arriba tu codigo y en principio vi que tienes un error en el codigo SQL del Delete.
La forma general es DELETE FROM <tabla> WHERE <condicion>.
Vos estas usando DELETE * que no es una sentencia valida de SQL.
Saludos


Carlos
23 de Febrero del 2006
Estimado Daniel:

Lei muy por arriba tu codigo y en principio vi que tienes un error en el codigo SQL del Delete.
La forma general es DELETE FROM <tabla> WHERE <condicion>.
Vos estas usando DELETE * que no es una sentencia valida de SQL.
Saludos


xxx
23 de Febrero del 2006
tengo un problema y buscando en internet me encontre con esta interrogante que se asemeja a la mia.

En mi caso, dependiendo de un filtro de seleccion se despliegan un conjunto de opciones, la idea es seleccionar aquellos registros que se deseen y guardar la seleccion en la Base de Datos, aun no logro guardar los registros seleccionados y queria saber si es posible que me ayudaran

Jos?ulian Gaviria Gomez
23 de Febrero del 2006
Veo que todos trabajan en acces, y si es sql server, y con el modelo de 3 capas, veamos:
El primer archivo se llama;
admon_prfles.asp y por medio de un checkbox puedo seleccionar uno o varios registros a ser borrados.

<% @LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>

<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft FrontPage 5.0">
<TITLE></TITLE>
<!--Esta es la ruta del archivo de estilos-->
<link rel='stylesheet' href='../css/estilos.css'>
</HEAD>

<BODY><!--<B>Formulario para guardar y actualizar información</b>-->
<br>
<p><!--#include file="ado.inc"--></p>
<p style="text-align: center">
<A href="../administracion/../administracion/admon_ingrso_prfles.htm">Ingresar nuevo </a>

<%
Dim Mv, PageNo,j,i, perfil,pagecount,idprfil, vrble
dim vector()

Mv = Request("Mv")


If Request("PageNo") = "" Then
PageNo = 1
Else
PageNo = Request("PageNo")
End If
' Setup Query Recordset (4 records per page)
%>
<p><!--#include file="verificar1.inc"--></p>


<%

rs.PageSize = 4


' Adjust PageNumber as Appropriate

If Mv = "pagina arriba" or Mv = "pagina abajo" Then
Select Case Mv
Case "pagina arriba"
If PageNo > 1 Then
PageNo = PageNo - 1
Else
PageNo = 1
End If
Case "pagina abajo"
If rs.AbsolutePage < rs.PageCount Then
PageNo = PageNo + 1
Else
PageNo = rs.PageCount
End If
Case Else
PageNo = 1
End Select
End If

rs.AbsolutePage = PageNo
%>
<%
response.write("Pagina ")
response.write(pageno)
response.write(" de ")
response.write(RS.PageCount)
%>


<!-- Draw Table of Contacts in DB -->
<table border="1" cellpadding="0" cellspacing="1" bordercolor="#b3b5c1" width="581">
<tr><th colspan=3 width="575">Manejo de perfiles</th></tr>

<td width="57" class=subTituloLista>CODIGO
<td width="389" class=subTituloLista>NOMBRE
<td width="209" class=subTituloLista>Seleccionar

<form name ="ingresar" method=post action="admon_brrar_prfles.asp">



<%
For j = 1 to rs.PageSize
redim vector(j)%>
<TR>
<%idprfil= rs("Pe_chr_id_prfil")
i=j%>
<TD VALIGN=TOP width="57" align="left">
<A href="../administracion/admon_mdfccon_prfles.asp?idprfil=<%=idprfil%>"><%= rs("Pe_chr_id_prfil") %>
</a>&nbsp;</TD>
<TD VALIGN=TOP width="389" align="left"><%= rs("pe_vhr_nmbre_prfil") %>
&nbsp;</TD>
<TD VALIGN=TOP width="209" align="left">
<p align="center">
<INPUT TYPE="CHECKBOX" NAME="idprfil" VALUE="<%=idprfil%>">&nbsp;</TD>
<!--<B>en este checkbox viene el id o los id a ser borrados</b>-->
</TR>

<%
rs.MoveNext

' Don't try to print the EOF record.
If rs.EOF Then
Exit For
End If
Next
%>
</TABLE>
<td colspan=2 class=button>
<input type='submit' class=button value='Eliminar' name='opcion'> </p>
</Form>

</p>

<Form Action=admon_prfles.asp Method="POST">
<Input Type="Hidden" Name="PageNo" Value="<%= PageNo %>">
<!-- Only show appropriate buttons -->
<% If PageNo < rs.PageCount Then %>
<INPUT TYPE="Submit" Name="Mv" Value="pagina abajo">
<% End If %>

<% If PageNo > 1 Then %>
<INPUT TYPE="Submit" Name="Mv" Value="pagina arriba">
<% End If %>
</Form>

</BODY>

</HTML>

el de borrar se llama
admon_brrar_prfles.asp

<% @ LANGUAGE="VBSCRIPT" %>
<%option explicit%>


<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>

<BODY bgcolor="white" topmargin="10" leftmargin="10">

<!-- Display Header -->

<font size="4" face="Arial, Helvetica">
<b></b></font><p>

<%
Dim conexion, resultado, resultado1
Dim strConn, elmnarprfil, rbrrarprfil
Dim oCmd, ocmd1
Dim oRs, registros
%>
<p><!--#include file="ado1.inc"--></p>
<%

dim Pe_chr_id_prfil 'almacena el id del perfil
dim variable, j, i, l, p,n
dim vector() 'vector donde almaceno los datos a ser borrados

l = 0
i = 1 ' posicion inicial del vector desde donde se toma la variable para separar los id´s a borrar
variable=request.form("idprfil")' viene el dato o los datos a ser borrados
if variable <> "" then 'verifico que existan datos a borrar

variable = variable & "," ' agrego una coma para terminación de los id a ser borrados
n = trim(len(variable))'tomo el valor de la vble eliminando espacios en ambos lados
redim vector(n) 'redimensiono el vector con el tamaño de la variable

for j = 1 to n ' Este bucle separa los diferentes id´s para ser borrados ya que vienen separados por coma
if mid(variable,j,1) = "," then
l = l +1' subindice del vector
p = j - i '
vector(l) = mid(variable,i,p)
'response.write(vector(l))
i = j +1
end if
next
%>
<%
for j = 1 to l
Pe_chr_id_prfil=vector(j)' Tomo los id del vector y los voy borrando
%>
<p><!--#include file="consultar1.inc"--></p>
<%
if not resultado.eof or not resultado1.eof then
%>

<p align="center">
<font color=blue size=1 face="verdana">
El perfil <%response.write(Pe_chr_id_prfil)%> presenta movimiento y no puede ser borrado.
<br>
<td><a href="admon_prfles.asp" > Regresar </a></td>
<%else%>
<p align="center">
<font color=blue size=1 face="verdana">
<p><!--#include file="borrar.inc"--></p>
Perfil <%response.write(Pe_chr_id_prfil)%> borrado con exito
<br>
<td><a href="admon_prfles.asp">Regresar</a></td>

<br>
<%end if%>

<%next
else%>
<p align="lefth">
<font color=blue size=1 face="verdana">

<%response.write("No selecciono un dato para borrar")%>
<br>
<td><a href="admon_prfles.asp">Regresar</a></td>
<br>
<%
end if%>
</font>
</body>
</html>

y los archivos incluidos son:

ado1.inc

<!--**************************************************************************************-->
<!--Nombre: ado1.inc -->
<!--Funcionalidad: Establece la conexión con la bd -->
<!--Identificador i/o: oconn, ocmd, ocmd1 -->
<!--Documentación: En este archivo se realiza consultas invocando el objeto "command"-->
<!-- que permite realizar varias consultas a la bd -->
<!--Comentarios: Se hace una conexion con la bd con el objeto command -->
<!--Autor: Julián Gaviria-->
<!--Fecha: Noviembre 1 03 -->
<!--**************************************************************************************-->

<%
Set conexion = Server.CreateObject("ADODB.Connection") 'Conexion a la base de datos
set oCmd = Server.CreateObject("ADODB.Command") 'Creación del objeto comando para consulta
Set oCmd1 = Server.CreateObject("ADODB.Command") 'Creación del objeto comando para consulta
strConn="driver=SQL Server;server=familiar;uid=;pwd=;database=db_siscorre" 'Conexion a la bd
conexion.Open strConn 'Abre la bd
Set oCmd.ActiveConnection = conexion 'Activa la conexion por medio del objeto comando
Set oCmd1.ActiveConnection = conexion 'Activa la conexion por medio del objeto comando

%>

consultar1.inc

<!--******************************************************************************-->
<!--Nombre: consultar1.inc -->
<!--Funcionalidad: manejo de cadena de sql para verificar si existe el dato -->
<!-- a ser borrado -->
<!--Identificador i/o: variables -->
<!--Documentación: Este es invocado al consultar -->
<!--Comentarios: Valida si existe o no el id -->
<!--Autor: Julián Gaviria -->
<!--Fecha: octubre 19/03 -->
<!--******************************************************************************-->

<%
dim ps_chr_cdgo_pis' almacena el codigo del pais
dim verificarpais, verificarperfil, vrfcarprflusro,vrfcarprflprmsos, vrfcarpgna ' se almacena las consultas a ser realizada por el procedimiento almacenado
dim rpais, rperfil, rprfilusro, rprfilprmsos, rvrfcarpgna

'ejecuto el objeto command con la primer cadena a consultar
oCmd.CommandText = "SELECT * FROM tbl_prmsos WHERE tbl_prmsos.Pm_chr_id_prfil=" & Pe_chr_id_prfil
set resultado = oCmd.execute

'ejecuto el objeto command1 con la segunda cadena a consultar
oCmd1.CommandText = "SELECT * FROM tbl_usros WHERE tbl_usros.us_chr_prfil_usro=" & Pe_chr_id_prfil
set resultado1 = oCmd1.execute


%>

ado.inc

<!--******************************************************************************-->
<!--Nombre: ado.inc -->
<!--Funcionalidad: Establece la conexión con la bd -->
<!--Identificador i/o: conexion, rs -->
<!--Documentación: Este es invocado por los diferentes archivos que requieren-->
<!-- conexion a la base de datos -->
<!--Comentarios: Se hace una conexion con la bd -->
<!--Autor: Julián Gaviria, Luz Marina, Jorge Ivan Gil
<!--Fecha: Noviembre 1 03 -->
<!--******************************************************************************-->
<%
dim conexion, rs,ru, rp, rpgnas

set conexion = server.CreateObject("ADODB.CONNECTION")
Conexion.Open "driver=SQL Server;server=familiar;uid=;pwd=;database=db_siscorre"
set rs=server.CreateObject("ADODB.RECORDSET")
set ru=server.CreateObject("ADODB.RECORDSET")
set rp=server.CreateObject("ADODB.RECORDSET")
set rpgnas=server.CreateObject("ADODB.RECORDSET")

%>

y borrar.inc

<!--******************************************************************************-->
<!--Nombre: inserciudad.inc -->
<!--Funcionalidad: manejo de cadena de sql para ingresar o verificar -->
<!--Identificador i/o: insertar, cadena, rs, conexion -->
<!--Documentación: Este es invocado al grabar la ciudad -->
<!--Comentarios: Valida si existe o no la ciudad -->
<!--Autor: Julián Gaviria
<!--Fecha: octubre 19/03 -->
<!--******************************************************************************-->

<%
dim us_chr_dcmnto_idntdad, elmnarusro, rbrrarusro, Pm_chr_id_prfil, pm_chr_id_pgna
dim elmnarprmso, rbrrarprmso, pg_chr_id_pgna, elmnarpgna, rbrrarpgna

elmnarprfil="exec borrar "+"'tbl_prfles'"+","+"'Pe_chr_id_prfil=''"+trim(Pe_chr_id_prfil)+"'''"
set rbrrarprfil = conexion.Execute(elmnarprfil)

elmnarusro="exec borrar "+"'tbl_usros'"+","+"'us_chr_dcmnto_idntdad=''"+ltrim(rtrim(us_chr_dcmnto_idntdad))+"'''"
set rbrrarusro = conexion.Execute(elmnarusro)

elmnarprmso="exec borrar "+"'tbl_prmsos'"+","+"'Pm_chr_id_prfil=''"+ltrim(rtrim(Pm_chr_id_prfil))+"'' and pm_chr_id_pgna=''"+ltrim(rtrim(pm_chr_id_pgna))+"'''"
set rbrrarprmso = conexion.Execute(elmnarprmso)

elmnarpgna="exec borrar "+"'tbl_pgnas'"+","+"'pg_chr_id_pgna=''"+ltrim(rtrim(pg_chr_id_pgna))+"'''"
set rbrrarpgna = conexion.Execute(elmnarpgna)


espero les sirva, hasta luego
%>

daniel ivan
23 de Febrero del 2006
Bueno,ya he descubierto como se hace, por si a alguien le interesa.

No es una forma muy elegante, pero por lo menos funciona.

Es: en el archivo del formulario poner:

<!--Conexión a la base de datos y a la tabla Actividades -->
<% dim Ob_Conn, Ob_RS %>
<% Set Ob_Conn = Server.CreateObject("ADODB.Connection")
'Se conecta a la base de datos local. Va al directorio donde se encuentra el archivo ASP.
Ob_Conn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("baseDeDatosCamping.mdb"))
Set Ob_RS=Ob_Conn.Execute("SELECT * FROM Actividades")
%>
<!--Cuando se pulsa el boton eliminar,se llama a la pagina paginaEliminarActividades, que
eliminará las actividades seleccionadas en el checkbox-->

<form name="formCheckBoxEliminarActividad" method="get" action="paginaEliminarActividades.asp">

<TABLE BORDER=1>
<TR>
<TD></TD> <!--En esta columna ira un checkbox por cada registro-->
<TD> HORA DE INICIO </TD>
<TD> HORA DE FIN </TD>
<TD> ACTIVIDAD </TD>
<TD> LUGAR </TD>
<TD> </TD>

<% DO UNTIL Ob_RS.Eof %>

<!--Por cada elemento de la tablaActividades, se incluye un checkbox cuyo nombre será el id q tiene
su registro correspondiente en la tabla-->
<%'Variable que contiene el id del registro
dim idReg%>
<TR>
<TD><input type="checkBox" name="<%=Ob_RS("Id")%>" value="" > </TD>
<TD> <%=Ob_RS("Inicio")%> </TD>
<TD> <%=Ob_RS("Fin")%> </TD>
<TD> <%=Ob_RS("Actividad")%> </TD>
<TD> <%=Ob_RS("Lugar")%> </TD>
<%idReg=Ob_RS("Id")
<TD> <A REF="paginaModificarActividad.asp?idReg"> Modificar </A> </TD>
<%Ob_RS.MoveNext
LOOP
Ob_RS.Close
Ob_Conn.Close %>
</TABLE>

<input type="submit" name="botonEliminar" value="Eliminar">
</form>

y en el archivo "paginaEliminarActividades.asp":

<!--Procedimiento que da de baja una actividades seleccionadas por el usuario a través de unos
CheckBox-->
<% SUB bajaActividad()
<!--**Se conecta a la base de datos-->
Set Ob_Conn=Server.CreateObject("ADODB.Connection")
' Creación de un objeto command para ejecutar comandos sobre la base de datos
Set Ob_Command=Server.CreateObject("ADODB.Command")
'Se conecta a la base de datos local
Ob_Conn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("baseDeDatosCamping.mdb"))
'Se indica al objeto command la base de datos activa, q sera sobre la q se ejecuten
'los comandos.
Ob_Command.ActiveConnection=Ob_Conn

FOR EACH var IN Request.QueryString %>
<!--Si el checkBox correspondiente a este registro, está seleccionado, se borra el registro-->
<% IF isnumeric(var) THEN
response.write "Id borrado" & var %> <BR> <%
Ob_Command.CommandText="DELETE FROM actividades WHERE Id=" & var
Ob_Command.Execute
END IF
NEXT

Ob_Conn.Close
Response.Redirect ("paginaIntroduccionActividadesDiarias.asp") 'Abro la pagina de introduccion de actividades diarias, para que se muestren los cambios

END SUB %> <!--Fin del procedimiento bajaActividad-->


x
23 de Febrero del 2006
x

Felix Caballero
23 de Febrero del 2006
Hola Daniel,

He seguido los pasos que indicas para poder borrar varios registros mediante un checkBox pero no hay manera que me funciones la página equivalente a EliminarActividades.

Te envio el código a ver si le pedes echar un vistazo. Muchas gracias por anticipado.

Página del formulario (borra_espect00-c.asp):
<%@LANGUAGE="VBSCRIPT" LCID = 1034%>
<!--#include file="../Connections/invitacions.asp" -->
<%
Dim rsespect__MMColParam
rsespect__MMColParam = "1"
If (Request.QueryString("nomespect") <> "") Then
rsespect__MMColParam = Request.QueryString("nomespect")
End If
%>
<%
Dim rsespect__MMColParamlocal
rsespect__MMColParamlocal = "1"
If (Request.QueryString("nomlocal") <> "") Then
rsespect__MMColParamlocal = Request.QueryString("nomlocal")
End If
%>
<%
Dim rsespect__MMColParamprom
rsespect__MMColParamprom = "1"
If (Request.QueryString("nompromotor") <> "") Then
rsespect__MMColParamprom = Request.QueryString("nompromotor")
End If
%>
<%
Dim rsespect
Dim rsespect_numRows

Set rsespect = Server.CreateObject("ADODB.Recordset")
rsespect.ActiveConnection = MM_invitacions_STRING
If rsespect__MMColParam = "TOTS" Then
If rsespect__MMColParamlocal = "TOTS" Then
If rsespect__MMColParamprom = "TOTS" Then
rsespect.Source = "SELECT * FROM espectacles ORDER BY nom_espect ASC"
Else
rsespect.Source = "SELECT * FROM espectacles WHERE nom_promotor = '" + Replace(rsespect__MMColParamprom, "'", "''") + "' ORDER BY nom_espect ASC"
End if
Else
If rsespect__MMColParamprom = "TOTS" Then
rsespect.Source = "SELECT * FROM espectacles WHERE nom_local = '" + Replace(rsespect__MMColParamlocal, "'", "''") + "' ORDER BY nom_espect ASC"
Else
rsespect.Source = "SELECT * FROM espectacles WHERE nom_local = '" + Replace(rsespect__MMColParamlocal, "'", "''") + "' AND nom_promotor = '" + Replace(rsespect__MMColParamprom, "'", "''") + "' ORDER BY nom_espect ASC"
End if

End if
Else
If rsespect__MMColParamlocal = "TOTS" Then
If rsespect__MMColParamprom = "TOTS" Then
rsespect.Source = "SELECT * FROM espectacles WHERE nom_espect = '" + Replace(rsespect__MMColParam, "'", "''") + "' ORDER BY nom_espect ASC"
Else
rsespect.Source = "SELECT * FROM espectacles WHERE nom_espect = '" + Replace(rsespect__MMColParam, "'", "''") + "' AND nom_promotor = '" + Replace(rsespect__MMColParamprom, "'", "''") + "' ORDER BY nom_espect ASC"
End if
Else
If rsespect__MMColParamprom = "TOTS" Then
rsespect.Source = "SELECT * FROM espectacles WHERE nom_espect = '" + Replace(rsespect__MMColParam, "'", "''") + "' AND nom_local = '" + Replace(rsespect__MMColParamlocal, "'", "''") + "' ORDER BY nom_espect ASC"
Else
rsespect.Source = "SELECT * FROM espectacles WHERE nom_espect = '" + Replace(rsespect__MMColParam, "'", "''") + "' AND nom_local = '" + Replace(rsespect__MMColParamlocal, "'", "''") + "' AND nom_promotor = '" + Replace(rsespect__MMColParamprom, "'", "''") + "' ORDER BY nom_espect ASC"
End if
End if
End if
'rsespect.Source = "SELECT * FROM espectacles WHERE nom_espect = '" + Replace(rsespect__MMColParam, "'", "''") + "' AND nom_local = '" + Replace(rsespect__MMColParamlocal, "'", "''") + "' AND nom_promotor = '" + Replace(rsespect__MMColParamprom, "'", "''") + "' ORDER BY nom_espect ASC"
rsespect.CursorType = 0
rsespect.CursorLocation = 2
rsespect.LockType = 1
rsespect.Open()

rsespect_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 25
Repeat1__index = 0
rsespect_numRows = rsespect_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

Dim rsespect_total
Dim rsespect_first
Dim rsespect_last

' set the record count
rsespect_total = rsespect.RecordCount

' set the number of rows displayed on this page
If (rsespect_numRows < 0) Then
rsespect_numRows = rsespect_total
Elseif (rsespect_numRows = 0) Then
rsespect_numRows = 1
End If

' set the first and last displayed record
rsespect_first = 1
rsespect_last = rsespect_first + rsespect_numRows - 1

' if we have the correct record count, check the other stats
If (rsespect_total <> -1) Then
If (rsespect_first > rsespect_total) Then
rsespect_first = rsespect_total
End If
If (rsespect_last > rsespect_total) Then
rsespect_last = rsespect_total
End If
If (rsespect_numRows > rsespect_total) Then
rsespect_numRows = rsespect_total
End If
End If
%>
<%
Dim MM_paramName
%>
<%
' *** Move To Record and Go To Record: declare variables

Dim MM_rs
Dim MM_rsCount
Dim MM_size
Dim MM_uniqueCol
Dim MM_offset
Dim MM_atTotal
Dim MM_paramIsDefined

Dim MM_param
Dim MM_index

Set MM_rs = rsespect
MM_rsCount = rsespect_total
MM_size = rsespect_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%>
<%
' *** Move To Record: handle 'index' or 'offset' parameter

if (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 If

End If
%>
<%
' *** Move To Record: if we dont know the record count, check the display range

If (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
Wend
End If
%>
<%
' *** Move To Record: update recordset stats

' set the first and last displayed record
rsespect_first = MM_offset + 1
rsespect_last = MM_offset + MM_size

If (MM_rsCount <> -1) Then
If (rsespect_first > MM_rsCount) Then
rsespect_first = MM_rsCount
End If
If (rsespect_last > MM_rsCount) Then
rsespect_last = MM_rsCount
End If
End If

' set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%>
<%
' *** Move To Record: update recordset stats

' set the first and last displayed record
rslocals_first = MM_offset + 1
rslocals_last = MM_offset + MM_size

If (MM_rsCount <> -1) Then
If (rslocals_first > MM_rsCount) Then
rslocals_first = MM_rsCount
End If
If (rslocals_last > MM_rsCount) Then
rslocals_last = MM_rsCount
End If
End If

' set the boolean used by hide region to check if we are on the last record
MM_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 parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For 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 If
Next

' add the Form variables to the MM_keepForm string
For 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 If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then
MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<%
' *** Move To Record: set the strings for the first, last, next, and previous links

Dim MM_keepMove
Dim MM_moveParam
Dim MM_moveFirst
Dim MM_moveLast
Dim MM_moveNext
Dim MM_movePrev

Dim MM_urlStr
Dim MM_paramList
Dim MM_paramIndex
Dim MM_nextParam

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' if the page has a repeated region, remove 'offset' from the maintained parameters
If (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 If
End If

' set the strings for the move to links
If (MM_keepMove <> "") Then
MM_keepMove = MM_keepMove & "&"
End If

MM_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
%>
<html>
<head>
<title>PDAentrada.com - Anul&middot;laci&oacute;d'espectacles (invitacions)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../estils.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.Estilo1 {
color: #FFFFFF;
font-weight: bold;
}
.Estilo2 {color: #FFFFFF}
-->
</style>
</head>

<body>
<% If Not rsespect.EOF Or Not rsespect.BOF Then %>
<br>
<form action="borra_espect01-c.asp" method="get" name="form" id="form">
<table width="500" border="0" align="center">
<tr>
<td colspan="6" bgcolor="#0000FF" class="titolstaula">
<div align="center" class="titolstaula">ANUL&middot;LACI&Oacute; DELS ESPECTACLES</div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="textnegre">&nbsp;</td>
<td class="textnegre">&nbsp;</td>
<td class="textnegre">&nbsp;</td>
<td class="textnegre">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2" bordercolor="#ECE9D8" bgcolor="#0000FF" class="textnegre"><div align="center" class="Estilo1">Anul&middot;lar</div>
<div align="center"><span class="Estilo2"></span></div></td>
<td bordercolor="#ECE9D8" bgcolor="#0000FF" class="textnegre"><div align="center" class="Estilo2"><strong>Espectacle</strong></div></td>
<td bordercolor="#ECE9D8" bgcolor="#0000FF" class="textnegre"><div align="center" class="Estilo2"><strong>Local</strong></div></td>
<td bordercolor="#ECE9D8" bgcolor="#0000FF" class="textnegre"><div align="center" class="Estilo2"><strong>Promotor</strong></div></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsespect.EOF))
%>
<tr>
<td width="10">&nbsp;</td>
<% dim idReg %>
<td colspan="2" class="textnegre"><div align="center"><A></A>
<input name="<%=(rsespect.Fields.Item("IdEspect").Value)%>" type="checkbox" id="<%=(rsespect.Fields.Item("IdEspect").Value)%>" value="idReg">
</div></td>
<td class="textnegre"><%=(rsespect.Fields.Item("nom_espect").Value)%></td>
<td class="textnegre"><%=(rsespect.Fields.Item("nom_local").Value)%></td>
<td class="textnegre"><%=(rsespect.Fields.Item("nom_promotor").Value)%></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsespect.MoveNext()
Wend
%>
<tr>
<td width="10">&nbsp;</td>
<td colspan="4">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="6">
<div align="center">
<input type="submit" name="Submit" value="Esborrar?">
</div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="4">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="6">
<div align="center">
<table width="50%" border="0" align="center" cellspacing="5" class="textnegre">
<tr>
<td width="23%" align="center">
<% If MM_offset <> 0 Then %>
<a href="<%=MM_moveFirst%>">Primer</a>
<% End If ' end MM_offset <> 0 %></td>
<td width="31%" align="center">
<% If MM_offset <> 0 Then %>
<a href="<%=MM_movePrev%>">Anterior</a>
<% End If ' end MM_offset <> 0 %>
</td>
<td width="23%" align="center">
<% If Not MM_atTotal Then %>
<a href="<%=MM_moveNext%>">Seg&uuml;ent</a>
<% End If ' end Not MM_atTotal %></td>
<td width="23%" align="center">
<% If Not MM_atTotal Then %>
<a href="<%=MM_moveLast%>">&Uacute;ltim</a>
<% End If ' end Not MM_atTotal %>
</td>
</tr>
</table>
<span class="textnegre"></span></div></td>
</tr>
<tr>
<td colspan="6">&nbsp;</td>
</tr>
<tr>
<td colspan="6">&nbsp;</td>
</tr>
<tr>
<td colspan="6"><div align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="103" height="24">
<param name="BGCOLOR" value="">
<param name="movie" value="flash/tornar.swf">
<param name="quality" value="high">
<param name="base" value=".">
<embed src="flash/tornar.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="103" height="24" ></embed>
</object>
</div></td>
</tr>
</table>
</form>
<% End If ' end Not rsespect.EOF Or NOT rsespect.BOF %>
<% If rsespect.EOF And rsespect.BOF Then %>
<table width="500" border="0" align="center">
<tr>
<td colspan="3" bgcolor="#0000FF" class="titolstaula">
<div align="center" class="titolstaula">ANUL&middot;LACI&Oacute; DELS ESPECTACLES</div></td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsespect.EOF))
%>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsespect.MoveNext()
Wend
%>
<tr>
<td width="10">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3">
<div align="center" class="titols"> NO EXISTEIX CAP REGISTRE QUE ACOMPLEIXI LES CONDICIONS DE RECERCA. GR&Agrave;CIES </div></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3"><div align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="103" height="24">
<param name="BGCOLOR" value="">
<param name="movie" value="flash/tornar.swf">
<param name="quality" value="high">
<param name="base" value=".">
<embed src="flash/tornar.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="103" height="24" ></embed>
</object>
</div></td>
</tr>
</table>
<% End If ' end rsespect.EOF And rsespect.BOF %>

</body>
</html>
<%
rsespect.Close()
Set rsespect = Nothing
%>

Página de anulación de los registros (borra_espect01-c.asp):
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/invitacions.asp" -->
<%
Dim rsespect
Dim rsespect_numRows

Set rsespect = Server.CreateObject("ADODB.Recordset")
rsespect.ActiveConnection = MM_invitacions_STRING
rsespect.Source = "SELECT * FROM espectacles ORDER BY IdEspect ASC"
rsespect.CursorType = 0
rsespect.CursorLocation = 2
rsespect.LockType = 1
rsespect.Open()

rsespect_numRows = 0
%>
<!--Procedimiento que da de baja una actividades seleccionadas por el usuario a través de unos
CheckBox-->
<% SUB bajaActividad()

FOR EACH idReg IN Request.QueryString %>
<!--Si el checkBox correspondiente a este registro, está seleccionado, se borra el registro-->
<% IF isnumeric(idReg) THEN
response.write "Id borrado" & idReg %> <BR> <%
Ob_Command.CommandText="DELETE FROM espectacles WHERE IdEspect=" & idReg
Ob_Command.Execute
END IF
NEXT


END SUB %> <!--Fin del procedimiento bajaActividad-->



<html>
<head>
<title>PDAentrada.com - Anul&middot;laci&oacute; d'espectacles (invitacions)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../estils.css" rel="stylesheet" type="text/css">
</head>

<body>
<br>
</body>
</html>
<%
rsespect.Close()
Set rsespect = Nothing
%>

daniel ivan
23 de Febrero del 2006
Estimado Daniel Iván, buscando buscando en Internet encotré tu nota sobre los checkbox, eliminar, etc.
Me haz dado una gran ayuda!!!
Mil GRACIAS!!!!!!!!!!!!!!!!!
Sergio Casais
Montevideo
Uruguay

Jos?ulian Gaviria Gomez
23 de Febrero del 2006
Favor mirar mas abajo.

guapo
23 de Febrero del 2006
Señores se complican la existencia yo les sugiero que usen un hidden y cuando den click en el checket pues ponerlo en el hidden y posteriormente enviarle la cadena algo asi http://patito/patito.asp?borrarreg=1,2,2,3,3,3

Pavel
23 de Febrero del 2006
Me parece bien, y funciona que es lo mas importante
Thanks a lot!!!!!

Paola
23 de Febrero del 2006
Gracias!!! desde Mexico
Es super padre que nos ayudemos desde tan lejos
bye

Allan
23 de Febrero del 2006
hola les doy una forma sencilla de hacer eso sin poner todoooooooo el codigo de lo que estan haciendo ;) si tienes una lista de items y al lado su checkbox para marcar(espero que el checkbox tenga en el value el id del item mostrado) lo que haces cuando haces el submit es lo siguiente:

Dim i
for i=1 to Request.form("id_chebox").count

sql = "delete from tabla where id_item = " & Request.form("id_checbox")(i) & ""

Next

asi te va a ir borrando todos lo que hayas seleccionado. Espero que les aydue en algo, chau

Orev
23 de Febrero del 2006
PIPI ES MUY LINDO!!!!

Orev
23 de Febrero del 2006
PIPI TE MANDO BESILLOS

kikesama laden
23 de Febrero del 2006
Daniel, te pasaste....gracias por la ayuda que diste, aúnque al principio la buscaste en el resto del foro, tu ayuda al final sirvió para muchos por tu buena predisposición a compartir con quienes sabemos menos. Ya sabés...la próxima, cuando tengas dudas, y aunque no la encuentres, igual seguí entrando en este foro para ayudar!
Saludos desde Santiago de Chile, y gracias en nombre de todos los que aprovechan igual tu codigo sin decirte: GRACIAS!