Ayuda con este BuildCriteria!!!
Publicado por Victor Manuel (101 intervenciones) el 16/06/2007 01:24:13
Tengo en un formulario tres combobox para filtrar informacion a un subformulario y de ahi a un informe, tengo un boton que se llama filtrar que me filtra la informacion seleccionada al subformulario.
Este es el codigo:
Private Sub Image46_Click()
Dim strfiltro As String, _
strEmpresa As String, _
strOrganizacion As String, _
strEmbarcacion As String, _
strPagado As String, _
Columna As Control
'Construyo la cadena para filtrar por Empresa
On Error GoTo Image46_Click_TratamientoErrores
If Not IsNull(Me.Empresa) And Me.Empresa <> "" Then
strEmpresa = BuildCriteria("Empresa", dbText, Me.Empresa)
Else
strEmpresa = ""
SubPendientes.Form.FilterOn = False
SubPendientes.Form.Filter = ""
End If
'Contruyo la cadena para ejecutar si Organización no es nulo
If Not IsNull(Me.Organizacion) And Me.Organizacion <> "" Then
strOrganizacion = BuildCriteria("Organizacion", dbText, Me.Organizacion)
Else
strOrganizacion = ""
SubPendientes.Form.FilterOn = False
SubPendientes.Form.Filter = ""
End If
'Construyo la cadena para ejecutar si Embarcación no es nulo
If Not IsNull(Me.Embarcacion) And Me.Embarcacion <> "" Then
strEmbarcacion = BuildCriteria("Embarcacion", dbText, Me.Embarcacion)
Else
strEmbarcacion = ""
SubPendientes.Form.FilterOn = False
SubPendientes.Form.Filter = ""
End If
'Construyo la cadena para filtrar si esta pagado o no
If Me.Pagado.Value = 0 Or Me.Pagado.Value = -1 Then
strPagado = BuildCriteria("Pagado", dbBoolean, Me.Pagado)
Else
strPagado = ""
SubPendientes.Form.FilterOn = False
SubPendientes.Form.Filter = ""
End If
' Según esten vacías o no las distintas cadenas construyo el filtro final
If strEmpresa <> "" Then
strfiltro = strEmpresa
Else
strfiltro = ""
End If
If strOrganizacion <> "" Then
If strfiltro <> "" Then
strfiltro = strfiltro & " AND " & strOrganizacion
Else
strfiltro = strOrganizacion
End If
End If
If strEmbarcacion <> "" Then
If strfiltro <> "" Then
strfiltro = strfiltro & " AND " & strEmbarcacion
Else
strfiltro = strEmbarcacion
End If
End If
If strPagado <> "" Then
If strfiltro <> "" Then
strfiltro = strfiltro & " AND " & strPagado
Else
strfiltro = strPagado
End If
End If
If strfiltro <> "" Then
Form_SubPendientes.Filter = strfiltro
Form_SubPendientes.FilterOn = True
Else
Form_SubPendientes.Filter = ""
Form_SubPendientes.FilterOn = False
End If
' ajusto el ancho de cada columna del subformulario
On Error Resume Next
For Each Columna In Me.SubPendientes.Form.Controls
Columna.FontName = "Verdana"
Columna.ColumnWidth = -2
Next
Image46_Click_Salir:
On Error GoTo 0
Exit Sub
Image46_Click_TratamientoErrores:
MsgBox "Error " & Err.Number & " en proc.:(" & Err.Description & ")"
Resume Image46_Click_Salir
End Sub
El caso esta en que el combobox que me busca or organizacion tiene 4 opciones:
ASTROMAR, S.A.
CONSULTORES
INSPECTORES
SISTEMARIN
Cuando filtro informacion por organizacion y selecciono por ejemplo CONSULTORES me filtra perfecto y con INSPECTORES Y SISTEMARIN tambien, el problema viene cuando quiero filtrar por ASTROMAR, S.A. me manda el error numero 2432.
Que dice que el valor que puse tiene un error de sintaxis y que debo encerrar los datos entre comillas.
No se que hacer para que me busque tanto texto como texto con puntos y comas.
¿Alguien podria decirme alguna solucion a esto, que ya llevo dandole vueltas un buen rato?
Saludos
Victor.
Este es el codigo:
Private Sub Image46_Click()
Dim strfiltro As String, _
strEmpresa As String, _
strOrganizacion As String, _
strEmbarcacion As String, _
strPagado As String, _
Columna As Control
'Construyo la cadena para filtrar por Empresa
On Error GoTo Image46_Click_TratamientoErrores
If Not IsNull(Me.Empresa) And Me.Empresa <> "" Then
strEmpresa = BuildCriteria("Empresa", dbText, Me.Empresa)
Else
strEmpresa = ""
SubPendientes.Form.FilterOn = False
SubPendientes.Form.Filter = ""
End If
'Contruyo la cadena para ejecutar si Organización no es nulo
If Not IsNull(Me.Organizacion) And Me.Organizacion <> "" Then
strOrganizacion = BuildCriteria("Organizacion", dbText, Me.Organizacion)
Else
strOrganizacion = ""
SubPendientes.Form.FilterOn = False
SubPendientes.Form.Filter = ""
End If
'Construyo la cadena para ejecutar si Embarcación no es nulo
If Not IsNull(Me.Embarcacion) And Me.Embarcacion <> "" Then
strEmbarcacion = BuildCriteria("Embarcacion", dbText, Me.Embarcacion)
Else
strEmbarcacion = ""
SubPendientes.Form.FilterOn = False
SubPendientes.Form.Filter = ""
End If
'Construyo la cadena para filtrar si esta pagado o no
If Me.Pagado.Value = 0 Or Me.Pagado.Value = -1 Then
strPagado = BuildCriteria("Pagado", dbBoolean, Me.Pagado)
Else
strPagado = ""
SubPendientes.Form.FilterOn = False
SubPendientes.Form.Filter = ""
End If
' Según esten vacías o no las distintas cadenas construyo el filtro final
If strEmpresa <> "" Then
strfiltro = strEmpresa
Else
strfiltro = ""
End If
If strOrganizacion <> "" Then
If strfiltro <> "" Then
strfiltro = strfiltro & " AND " & strOrganizacion
Else
strfiltro = strOrganizacion
End If
End If
If strEmbarcacion <> "" Then
If strfiltro <> "" Then
strfiltro = strfiltro & " AND " & strEmbarcacion
Else
strfiltro = strEmbarcacion
End If
End If
If strPagado <> "" Then
If strfiltro <> "" Then
strfiltro = strfiltro & " AND " & strPagado
Else
strfiltro = strPagado
End If
End If
If strfiltro <> "" Then
Form_SubPendientes.Filter = strfiltro
Form_SubPendientes.FilterOn = True
Else
Form_SubPendientes.Filter = ""
Form_SubPendientes.FilterOn = False
End If
' ajusto el ancho de cada columna del subformulario
On Error Resume Next
For Each Columna In Me.SubPendientes.Form.Controls
Columna.FontName = "Verdana"
Columna.ColumnWidth = -2
Next
Image46_Click_Salir:
On Error GoTo 0
Exit Sub
Image46_Click_TratamientoErrores:
MsgBox "Error " & Err.Number & " en proc.:(" & Err.Description & ")"
Resume Image46_Click_Salir
End Sub
El caso esta en que el combobox que me busca or organizacion tiene 4 opciones:
ASTROMAR, S.A.
CONSULTORES
INSPECTORES
SISTEMARIN
Cuando filtro informacion por organizacion y selecciono por ejemplo CONSULTORES me filtra perfecto y con INSPECTORES Y SISTEMARIN tambien, el problema viene cuando quiero filtrar por ASTROMAR, S.A. me manda el error numero 2432.
Que dice que el valor que puse tiene un error de sintaxis y que debo encerrar los datos entre comillas.
No se que hacer para que me busque tanto texto como texto con puntos y comas.
¿Alguien podria decirme alguna solucion a esto, que ya llevo dandole vueltas un buen rato?
Saludos
Victor.
Valora esta pregunta
0