Notifications
Clear all

Falha em combobox no formulário pesquisa

13 Posts
2 Usuários
0 Reactions
1,618 Visualizações
(@neri-s)
Posts: 0
New Member
Topic starter
 

Estou utilizando o codigo abaixo para preencher a minha combobox de pesquisa. Mas está com algum problema pois não pega todos os tipos que constam na coluna determinada.

Alguém pode me dar uma ajuda?

Sub Preenchercbopericia()

        Dim n As Long, texto As Variant
        Dim i As Integer
        Me.cbopericia.Clear
        
        For n = 1 To ListView1.ListItems.Count
            If Me.ListView1.ListItems(n).ListSubItems(4) = "" Then Exit For
            If InStr(texto, Me.ListView1.ListItems(n).ListSubItems(4)) = 0 Then
                texto = texto & "|" & Me.ListView1.ListItems(n).ListSubItems(4) '& "|"
            End If
        Next
            texto = Split(texto, "|")
        
        For i = 1 To UBound(texto)
            cbopericia.AddItem texto(i)
        Next
        
        Call Ordenarcbopericia
        
End Sub
 
Postado : 21/12/2016 1:06 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde NERI S,

Fica um pouco difícil analisar dessa maneira, mas aparentemente não vejo nada de errado no código...
Tenta remover essa linha:

If Me.ListView1.ListItems(n).ListSubItems(4) = "" Then Exit For

Qualquer coisa da o grito.
Abraço

 
Postado : 21/12/2016 1:31 pm
(@neri-s)
Posts: 0
New Member
Topic starter
 

Bernardo
fiz uns testes trocando a palavra que ele nao achava por outra tipo "teste" e ele acha certo...
Deve ter algo na palavra.... será que é por repetir tipo assim:

Tem:
Periculosidade
e tem:
Periculosidade e ruido

Será que ele se perde por repetir?

 
Postado : 21/12/2016 2:19 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Pode ser isso sim...
Se o "periculosidade" estiver depois ele vai pular... Mas se o "perixulosidade e ruido" estiver depois não...

Estou no celular agora... Mas tenta asssim:

If InStr("|" & texto & "|" Me.ListView1.ListItems(n).ListSubItems(4)) = 0 Then

Qualquer coisa da o grito.
Abraço

 
Postado : 21/12/2016 3:10 pm
(@neri-s)
Posts: 0
New Member
Topic starter
 

Pelos testes que fiz realmente deve ser isto.

Com a tua linha nao consegui resolver...
Vou fazendo testes. Se tiver mais uma sugestão, pode postar.

Abraço

 
Postado : 21/12/2016 3:27 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Trocou a sua linha pela minha?
Não funcionou?
Aconteceu o que?

 
Postado : 21/12/2016 3:42 pm
(@neri-s)
Posts: 0
New Member
Topic starter
 

Bom dia Bernardo
deixei assim, abaixo: (não deu resultado, simplesmente não mostra).

Sub Preenchercbopericia()

Dim n As Long, texto As Variant
Dim i As Integer
Me.cbopericia.Clear

For n = 1 To ListView1.ListItems.Count
If Me.ListView1.ListItems(n).ListSubItems(4) = "" Then Exit For
If InStr("|" & texto & "|", Me.ListView1.ListItems(n).ListSubItems(4)) = 0 Then
texto = texto & "|" & Me.ListView1.ListItems(n).ListSubItems(4)
End If
Next
texto = Split(texto, "|")

For i = 1 To UBound(texto)
cbopericia.AddItem texto(i)
Next

Call Ordenarcbopericia

End Sub

 
Postado : 22/12/2016 6:27 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Puts...
Inverti a ordem ali... Deixa assim:

    Sub Preenchercbopericia()

            Dim n As Long, texto As Variant
            Dim i As Integer
            Me.cbopericia.Clear
           
            For n = 1 To ListView1.ListItems.Count
                If Me.ListView1.ListItems(n).ListSubItems(4) = "" Then Exit For
                If InStr(texto, "|" & Me.ListView1.ListItems(n).ListSubItems(4) & "|") = 0 Then
                    texto = texto & "|" & Me.ListView1.ListItems(n).ListSubItems(4) '& "|"
                End If
            Next
                texto = Split(texto, "|")
           
            For i = 1 To UBound(texto)
                cbopericia.AddItem texto(i)
            Next
           
            Call Ordenarcbopericia
           
    End Sub

Qualquer coisa da o grito.
Abraço

 
Postado : 22/12/2016 7:31 am
(@neri-s)
Posts: 0
New Member
Topic starter
 

Agora funciona, mas com um pequeno detalhe:

Cada tipo ele repete 2 vezes. Veja no anexo.

 
Postado : 22/12/2016 12:38 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Estranho, mas nem todos se repetem. Tenta assim:

        Sub Preenchercbopericia()

                Dim n As Long, texto As Variant
                Dim i As Integer
                Me.cbopericia.Clear
               
                For n = 1 To ListView1.ListItems.Count
                    If Me.ListView1.ListItems(n).ListSubItems(4) = "" Then Exit For
                    If InStr(texto, "|" & trim(Me.ListView1.ListItems(n).ListSubItems(4)) & "|") = 0 Then
                        texto = texto & "|" & trim(Me.ListView1.ListItems(n).ListSubItems(4)) '& "|"
                    End If
                Next
                    texto = Split(texto, "|")
               
                For i = 1 To UBound(texto)
                    cbopericia.AddItem texto(i)
                Next
               
                Call Ordenarcbopericia
               
        End Sub
 
Postado : 22/12/2016 1:09 pm
(@neri-s)
Posts: 0
New Member
Topic starter
 

Bernardo,
ainda continua repetindo que nem antes..

 
Postado : 22/12/2016 1:36 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Tenta assim:

Option Explicit

Sub Preenchercbopericia()
Dim texto   As Variant
Dim n       As Long
Dim i       As Integer

    Me.cbopericia.Clear
    texto = "|"
    
    For n = 1 To ListView1.ListItems.Count - 1
        If InStr(texto, "|" & Trim(Me.ListView1.ListItems(n).ListSubItems(4)) & "|") = 0 Then
            texto = texto & Trim(Me.ListView1.ListItems(n).ListSubItems(4)) & "|"
        End If
    Next
    
    texto = Split(texto, "|")
    
    For i = 1 To UBound(texto)
        cbopericia.AddItem texto(i)
    Next
    
    Call Ordenarcbopericia
       
End Sub
 
Postado : 23/12/2016 7:50 am
(@neri-s)
Posts: 0
New Member
Topic starter
 

Bernardo,
Parece que está funcionando, pelo menos mostrou certo.

Poxa, desculpe tirar seu tempo. Muito Obrigado pela ajuda.
Abraço

 
Postado : 23/12/2016 4:05 pm