Ola mesters mais uma vez estou de volta com uma duvida, e mais uma vez necessito da vossa sabedoria.
Então é assim tenho uma macro que filra registos em um formulario continuo, nesse formulario eu tenho cerca de 10 campos e necessito de filtar por 5 deles: nome, nºbrigada. local, desnegocio, entassoc, então eu criei o codigo abaixo, com as devidas adaptações para cada um dos campos "filtro" Tx1 tx2, tx3,tx5,tx5 , mas não esta dando certo, não consigo perceber o que esta errado, é ai que preciso de vossa ajuda. este codigo é para o filtro de "desnegocio" usando tx4 como filtro
Private Sub tx4_Change()
j = 0
x = Me!tx4.Text
If Len(Me!tx4.Text & "") > 0 Then j = j + 1
If Len(Me!tx5 & "") > 0 Then j = j + 2
If Len(Me!tx3 & "") > 0 Then j = j + 3
If Len(Me!tx2 & "") > 0 Then j = j + 4
If Len(Me!tx1 & "") > 0 Then j = j + 5
Select Case j
Case 0
Me.Filter = ""
Me.FilterOn = False
Me!tx4.SetFocus
Exit Sub
Case 1
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*'"
' Case 2
' filtro = "cli_local Like '*" & Me!tx3 & "*'"
Case 3
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_Entassoc Like '*" & Me!tx5.Text & "*'"
Case 4
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*'"
Case 5
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_nome Like '*" & Me!tx2 & "*'"
Case 6
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_Entassoc Like '*" & Me!tx5 & "*' and cli_local Like '*" & Me!tx3 & "*'or cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 7
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_nome Like '*" & Me!tx2 & "*' and cli_Entassoc Like '*" & Me!tx5 & "*'"
Case 8
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_Nome Like '*" & Me!tx2 & "*' and cli_local Like '*" & Me!tx3 & "*'or cli_Entassoc Like '*" & Me!tx5.Text & "*' AND cli_DesNegocio Like '*" & Me!tx4 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 9
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'or cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 10
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_nome Like '*" & Me!tx2 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'or cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_Entassoc Like '*" & Me!tx5 & "*' and cli_local Like '*" & Me!tx3 & "*'or cli_Nome Like '*" & Me!tx2 & "*'"
Case 11
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_entassoc Like '*" & Me!tx5 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 12
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_entassoc Like '*" & Me!tx5 & "*' and cli_nome Like '*" & Me!tx2 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 13
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_nome Like '*" & Me!tx2 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
'Case 14
'filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_nome Like '*" & Me!tx2 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 15
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_entassoc Like '*" & Me!tx5 & "*' and cli_local Like '*" & Me!tx3 & "*' and cli_nome Like '*" & Me!tx2 & "*' cli_NºBrigada Like '*" & Me!tx1 & "*'"
End Select
Me.Filter = filtro
Me.FilterOn = True
Me!tx4 = x
Me!tx4.SelStart = Len(x & "")
End Sub
Então é assim tenho uma macro que filra registos em um formulario continuo, nesse formulario eu tenho cerca de 10 campos e necessito de filtar por 5 deles: nome, nºbrigada. local, desnegocio, entassoc, então eu criei o codigo abaixo, com as devidas adaptações para cada um dos campos "filtro" Tx1 tx2, tx3,tx5,tx5 , mas não esta dando certo, não consigo perceber o que esta errado, é ai que preciso de vossa ajuda. este codigo é para o filtro de "desnegocio" usando tx4 como filtro
Private Sub tx4_Change()
j = 0
x = Me!tx4.Text
If Len(Me!tx4.Text & "") > 0 Then j = j + 1
If Len(Me!tx5 & "") > 0 Then j = j + 2
If Len(Me!tx3 & "") > 0 Then j = j + 3
If Len(Me!tx2 & "") > 0 Then j = j + 4
If Len(Me!tx1 & "") > 0 Then j = j + 5
Select Case j
Case 0
Me.Filter = ""
Me.FilterOn = False
Me!tx4.SetFocus
Exit Sub
Case 1
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*'"
' Case 2
' filtro = "cli_local Like '*" & Me!tx3 & "*'"
Case 3
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_Entassoc Like '*" & Me!tx5.Text & "*'"
Case 4
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*'"
Case 5
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_nome Like '*" & Me!tx2 & "*'"
Case 6
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_Entassoc Like '*" & Me!tx5 & "*' and cli_local Like '*" & Me!tx3 & "*'or cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 7
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_nome Like '*" & Me!tx2 & "*' and cli_Entassoc Like '*" & Me!tx5 & "*'"
Case 8
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_Nome Like '*" & Me!tx2 & "*' and cli_local Like '*" & Me!tx3 & "*'or cli_Entassoc Like '*" & Me!tx5.Text & "*' AND cli_DesNegocio Like '*" & Me!tx4 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 9
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'or cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 10
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_nome Like '*" & Me!tx2 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'or cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_Entassoc Like '*" & Me!tx5 & "*' and cli_local Like '*" & Me!tx3 & "*'or cli_Nome Like '*" & Me!tx2 & "*'"
Case 11
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_entassoc Like '*" & Me!tx5 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 12
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_entassoc Like '*" & Me!tx5 & "*' and cli_nome Like '*" & Me!tx2 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 13
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_nome Like '*" & Me!tx2 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
'Case 14
'filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_local Like '*" & Me!tx3 & "*' and cli_nome Like '*" & Me!tx2 & "*' and cli_NºBrigada Like '*" & Me!tx1 & "*'"
Case 15
filtro = "cli_DesNegocio Like '*" & Me!tx4.Text & "*' AND cli_entassoc Like '*" & Me!tx5 & "*' and cli_local Like '*" & Me!tx3 & "*' and cli_nome Like '*" & Me!tx2 & "*' cli_NºBrigada Like '*" & Me!tx1 & "*'"
End Select
Me.Filter = filtro
Me.FilterOn = True
Me!tx4 = x
Me!tx4.SelStart = Len(x & "")
End Sub