CONSULTA SQL USANDO UM LISTBOX

USUARIO.EXCLUIDOS 16/07/2005 15:15:01
#94464
Pessoal
Tenho 2 TextBox onde o usuário define a data para consulta ex:(01/07/2005 a 31/07/2005) automaticamente o um ListBox carrega todas as áreas que estão relacionadas no período acima,logo após o usuário seleciona somente as áreas que lhe interessam então a SQL filtra as datas do textbox e as áreas do lstSelecionado para executar a consulta,porem quando a SQL consulta os dados do lstSelecionado no banco de dados a mesma não encontra.

Dim Onde As String
Dim Cond As Boolean

SQL = "Select Tipo_Incidente,Causa_Incidente,Status,Acidente From TbIncidentes "
Cond = False

If IsDate(txtData.Text) = True And IsDate(txtData1.Text) = True Then
If Cond = False Then
Onde = " Where Data Between #" & Format(txtData.Text, "mm/dd/yyyy") & "# And #" & Format(txtData1.Text, "mm/dd/yyyy") & "# "
Cond = True
Else
Onde = Onde & " AND Data Between #" & Format(txtData.Text, "mm/dd/yyyy") & "# And #" & Format(txtData1.Text, "mm/dd/yyyy") & "# "
End If
ElseIf IsDate(txtData.Text) = True Then
If Cond = False Then
Onde = " Where Data = #" & Format(txtData.Text, "mm/dd/yyyy") & "# "
Cond = True
Else
Onde = Onde & " AND Data = #" & Format(txtData.Text, "mm/dd/yyyy") & "# "
End If
ElseIf IsDate(txtData1.Text) = True Then
If Cond = False Then
Onde = " Where Data <= #" & Format(txtData1.Text, "mm/dd/yyyy") & "# "
Cond = True
Else
Onde = Onde & " AND Data <= #" & Format(txtData1.Text, "mm/dd/yyyy") & "# "
End If
End If
If lstSelecionado.ListCount > 0 Then
If Cond = False Then
Onde = " Where Setor_Envolvido ='" & lstSelecionado.ItemData(lstSelecionado.Index) & "'"
Cond = True
Else
Onde = Onde & " AND Setor_Envolvido ='" & lstSelecionado.ItemData(lstSelecionado.Index) & "'"
End If
End If

SQL = SQL & Onde
Dim RC As Recordset

'On Error GoTo Erro:
Set RC = BD.OpenRecordset(SQL, dbOpenSnapshot)
USUARIO.EXCLUIDOS 17/07/2005 00:50:16
#94537
set tabela=conexao.execute("Select Tipo_Incidente,Causa_Incidente,Status,Acidente From TbIncidentes")
if not tabela.eof then
do while not tabela.eof
lstDados.additem tabela("tipo_incidente")
tabela.movenext
loop
else
msgbox "Não foi possivel encontrar nada"
end if

eh isso, alguma dúvida só fala comigu
Tópico encerrado , respostas não são mais permitidas