Ver Mensaje Individual
  #10 (permalink)  
Antiguo 08/03/2008, 21:16
Avatar de juancho24
juancho24
 
Fecha de Ingreso: octubre-2007
Mensajes: 101
Antigüedad: 16 años, 7 meses
Puntos: 1
De acuerdo Re: busqueda por rango de fecha

Amigos me sale un error que no se a que se debe, por favor ayudenme, aqui les dejo el codigo marcado en donde me sale el error:

Error'-2147217900 (80040e14)`en tiempo de ejecucion:
se encontraron caracteres despúes del final de la instrucción SQL.



sql = " SELECT DATOSVISITADOR.RutVisitador, DATOSVISITADOR.DvVisitador, DATOSVISITADOR.NombreVisitador, DATOSCLIENTE.RutCliente, DATOSCLIENTE.DvCliente, DATOSCLIENTE.NombreCliente, OBSERVACIONESGENERALES.MontoCredito, OBSERVACIONESGENERALES.PlazoCredito, OBSERVACIONESGENERALES.NombrePersonaAtendio, OBSERVACIONESGENERALES.HoraVisita, OBSERVACIONESGENERALES.Fecha "
sql = sql & "FROM (DATOSCLIENTE INNER JOIN (DATOSVISITADOR INNER JOIN VISITAS ON (DATOSVISITADOR.DvVisitador = VISITAS.DvVisitador) AND (DATOSVISITADOR.RutVisitador = VISITAS.RutVisitador)) ON (DATOSCLIENTE.ID = VISITAS.ID) AND (DATOSCLIENTE.DvCliente = VISITAS.DvCliente) AND (DATOSCLIENTE.RutCliente = VISITAS.RutCliente)) LEFT JOIN OBSERVACIONESGENERALES ON (VISITAS.DvCliente = OBSERVACIONESGENERALES.DvCliente) AND (VISITAS.RutCliente = OBSERVACIONESGENERALES.RutCliente) AND (VISITAS.ID = OBSERVACIONESGENERALES.ID);"
rs1.Open sql & "(WHERE OBSERVACIONESGENERALES.FECHA BETWEEN #" & Txtfechainicio & "# AND #" & txtfechafin & "#)", cnn1, adOpenDynamic, adLockOptimistic

les agradesco su ayuda

saludos


Cita:
Iniciado por extrem_bcn Ver Mensaje
Por cierto, la sentencia SQL que tienes es.. guapa eh jejejeje en serio, si ves que te va mal mira de filtrarlo por yyyy/mm/dd (aunque con mm/dd/yyyy deberia de irte bien).

Por cierto, respecto el código que va después de la SQL... te corregiria lo siguiente:

If not (rs1.BOF And rs1.EOF) Then 'Es más fácil de leer con el not, no crees?
If isdate(Txtfechainicio) Or isdate(txtfechafin) Then 'Para que haces la comprobación si ya has hecho la SQL? lo lógico seria hacer este filtro al principio de todo ya que si abres el recordset sin fecha te va a pegar un pedo de aquí a HonoLulu (o como se escriba). y utilizaria el isdate en vez de ""

'Creo que aquí pretendres preguntar que si la fecha del rs1 es igual al txtfechainicio y al tctfechafin, no? pues te falta otro =

If rs1("fecha") = Txtfechainicio.Text And rs1("fecha") = txtfechafin.Text Then
Call CargarDataGrid(DataGrid1)
Else
MsgBox ("no hay datos para cargar"), vbInformation
End If
Else
MsgBox ("Debe seleccionar un dato"), vbCritical
com_grupo.Enabled = True
End If
Else
MsgBox ("La tabla no tiene registros"), vbCritical

End If

End Sub