Ver Mensaje Individual
  #4 (permalink)  
Antiguo 25/01/2008, 03:19
extrem_bcn
 
Fecha de Ingreso: julio-2007
Ubicación: Delante del PC (Barcelona
Mensajes: 157
Antigüedad: 17 años, 9 meses
Puntos: 2
Re: Sentencia SQL con CheckBoxs

Gracias por contestar!
Al final he hecho esto, por si a alguien le sirve (el fundamento es el tuyo):

Código:
'Pongo a 0 los contadores
    i = 0
    totalChk = 0
    blnPrimer = True

    'Hago las SQL
    strCon(0) = "concepto LIKE 'VP%'"
    strCon(1) = "concepto LIKE 'TA%'"
    strCon(2) = "concepto LIKE 'VA%'"
    strCon(3) = "concepto LIKE 'DP%'"
    strCon(4) = "concepto LIKE 'DR%'"
    strCon(5) = "concepto LIKE 'PK%'"
    strCon(6) = "concepto LIKE 'AL%'"
    
    'Cuento los CheckBox que hay Marcados
    Do While e <= chkCon.Count - 1
        If chkCon(e).Value = 1 Then
            totalChk = totalChk + 1
        End If
        e = e + 1
    Loop
    
    Do While i <= chkCon.Count - 1
        'Empiezo a crear la SQL
        If chkCon(i).Value = 1 Then
            ' Si es el primero AND ( concepto LIKE...
            If blnPrimer = True Then
                strSQL = strSQL & "AND (" & strCon(i)
                blnPrimer = False
            'Si no es el primero: sentencia con OR concepto LIKE...
            Else
                strSQL = strSQL & " OR " & strCon(i)
            End If
        End If
        i = i + 1
    Loop

    If totalChk > 0 Then ' Si se ha seleccionado algun CheckBox pongo ")" al final
        strSQL = strSQL & ")"
    End If
    
    'reestablezco los contadores
    i = 0
    totalChk = 0
    blnPrimer = True
  
    strSQL = "SELECT * FROM tabGastos WHERE empleado_dni ='" & DNI & "' " & strSQL & " ORDER BY fecha"