ERRO NA HORA DE PESQUISAR POR DATA

THULIO 09/09/2011 16:20:10
#383836
Estou fazendo um cadastro de residentes, e nele queria pesquisar por determinada data...usei esse codigo no botão pesquisar..



Private Sub Cmdpesquisa_Click()

If Not IsDate(Txtinicial.Text) Then
MsgBox [Ô]Data inicial inválida[Ô], vbCritical
Txtinicial.SetFocus
Exit Sub
End If
If Not IsDate(Txtfinal.Text) Then
MsgBox [Ô]Data final inválida[Ô], vbCritical
Txtfinal.SetFocus
Exit Sub
End If

Dim totalresid As Integer
listdata.Clear
tresidente.RecordSource = [Ô]select * from Masculino where Add between [Ô] & [Ô]#[Ô] & [Ô][Ô]
[txt-color=#e80000]Format(Txtinicial.Text, [Ô]MM/DD/YYYY[Ô]) & [Ô]#[Ô] & [Ô]AND[Ô] & [Ô]#[Ô] &[Ô][/txt-color]
tresidente.RecordSource = [Ô]select * from Masculino where Final between [Ô] & [Ô]#[Ô] & [Ô][Ô]
[txt-color=#e80000]Format(Txtfinal.Text, [Ô]MM/DD/YYYY[Ô]) & [Ô]#[Ô] & [Ô]Order by Data[Ô][/txt-color]
tresidente.Refresh
Do While Not tresidente.Recordset.EOF
[txt-color=#e80000]listdata.AddItem Tresidente.Recordset([Ô]Data[Ô]) & Space(1) &[/txt-color]
tresidente.Recordset ([Ô]Nome[Ô]) & Space(1) & tresidente.Recordset([Ô]Codigo[Ô]) & Space(1) & tresidente.Recordset([Ô]add[Ô])
totalresid = totalresid + tresidente.Recordset([Ô]Codigo[Ô])
tresidente.Recordset ([Ô]Quantidade[Ô])
tresidente.Recordset.MoveNext
Loop
Txtunidade.Text = totalresid
End Sub



o que ta de vermelho ta dando erro, erro de Syntax..o que to fazendo de errado?.
ROBIU 09/09/2011 17:08:11
#383845
Troca seu o trecho correspondente por:

Dim Sql As String
Dim totalresid As Integer
listdata.Clear

Sql = [Ô]select * from Masculino where Add between #[Ô]
Sql = Sql & Format(Txtinicial.Text, [Ô]MM/DD/YYYY[Ô]) & [Ô]# AND #[Ô]
Sql = Sql & Format(Txtfinal.Text, [Ô]MM/DD/YYYY[Ô]) & [Ô]# Order by Data[Ô]
tresidente.RecordSource = Sql
tresidente.Refresh

Do While Not tresidente.Recordset.EOF
MARCELO.TREZE 10/09/2011 06:26:07
#383875
lambança em filho, se a alteração que o colega ROBIU passou não funcionar tente esta abaixo

tresidente.RecordSource = [Ô]select * from Masculino where data Between #[Ô] & Format(Txtinicial.Text, [Ô]MM/DD/YYYY[Ô]) & [Ô]# AND #[Ô] & Format(Txtfinal.Text, [Ô]MM/DD/YYYY[Ô]) & [Ô]# Order by Data[Ô]
Tópico encerrado , respostas não são mais permitidas