Textbox input ricerca con carattere jolly



  • Textbox input ricerca con carattere jolly(*)
    di SAVYBACK (utente non iscritto) data: 30/08/2013 11:43:44

    Ciao a tutti,
    sto impazzendo con un codice, vorrei che la textbox "txtRicerca", dopo aver selezionato un criterio di ricerca previsto nel frame "frSelezionaCampo" (ce ne sono 6) potesse ricevere anche solo una parte del nome accompagnata o da un carattere jolly tipo "*" o dalle prime iniziali del nome e facesse vedere i risultati.
    Vi quoto il codice se potreste darmi gentilmente dei consigli...
    Grazie in anticipo a tutti!!


     
    
    '================================ 
    '===== Pulsanti frame Trova ===== 
    '================================ 
    Private Sub cmdIniziaRicerca_Click() 
    
        Dim Ctrl As Control 
        Dim lCampo As Long 
        Dim lRif As Long 
        Dim C As Range 
        Dim Rng As Range 
        Dim lUltRiga As Long 
        
        lCampo = 0 
        
        With Me 
              
           With .frSelezionaCampo 
            
                For Each Ctrl In .Controls 
                    If Ctrl.Value = True Then 
                        lCampo = Mid(Ctrl.Name, _ 
                        4, Len(Ctrl.Name)) 
                        
                    End If 
                Next 
            
            End With 
            
            If .txtRicerca <> "" And lCampo <> 0 Then 
            
                lUltRiga = sh.Range( _ 
                   "A" & Rows.Count).End(xlUp).Row 
              Set Rng = sh.Range("A2:V" & lUltRiga) 
                
                For Each C In Rng.Range( _ 
                    CELLS(1, lCampo), _ 
                    CELLS(lUltRiga, lCampo)) 
                   If C.Value = .txtRicerca.Text Then 
                        lRif = 4 - lCampo 
                        .txtID.Value = sh.CELLS(C.Row, 1).Value 
                        .TxtCause.Value = sh.CELLS(C.Row, 2).Value 
                        .txtldv.Value = sh.CELLS(C.Row, 3).Value 
                        .txtInvoice.Value = sh.CELLS(C.Row, 4).Value 
                        .txtawb.Value = sh.CELLS(C.Row, 5).Value 
                        .TxtDatum.Value = sh.CELLS(C.Row, 6).Value 
                        .txtiva.Value = sh.CELLS(C.Row, 7).Value 
                        .Texdatappp.Value = sh.CELLS(C.Row, 8).Value 
                        .Txtdataprat.Value = sh.CELLS(C.Row, 9).Value 
                        .cbodebtor.Value = sh.CELLS(C.Row, 10).Value 
                         .cboanno.Value = sh.CELLS(C.Row, 12).Value 
                        .txtimporto.Value = sh.CELLS(C.Row, 11).Value 
                        .cbocontenuto.Value = sh.CELLS(C.Row, 13).Value 
                        .cbomercato.Value = sh.CELLS(C.Row, 14).Value 
                        .cbopartner.Value = sh.CELLS(C.Row, 15).Value 
                        .cbonazione.Value = sh.CELLS(C.Row, 16).Value 
                        .txtposizione.Value = sh.CELLS(C.Row, 17).Value 
                        .cbostatus.Value = sh.CELLS(C.Row, 18).Value 
                        .txtnote.Value = sh.CELLS(C.Row, 20).Value 
                        .cboliability.Value = sh.CELLS(C.Row, 19).Value 
                        .Txtstart.Value = sh.CELLS(C.Row, 21).Value 
                        .txtend.Value = sh.CELLS(C.Row, 22).Value 
                        
                        lRigaAttiva = C.Row 
                        lRigaValoreTrovato = C.Row 
                        Exit For 
                    End If 
                Next 
            Else 
                MsgBox "No data or field selected", _ 
                    vbOKOnly, "Attention" 
            End If 
            
        End With 
                With Me.txtiva 
    .Value = Format(.Text, "00000000000") 
    
    End With 
        With Me.TxtDatum 
    .Value = Format(.Text, "dd/mm/yyyy") 
    End With 
    
     With Me.txtimporto 
    .Value = Format(.Text, "€ #,##0.00") 
    End With 
    
        Set Ctrl = Nothing 
        Set C = Nothing 
        Set Rng = Nothing 
        
    End Sub



  • di totygno71 (utente non iscritto) data: 30/08/2013 14:58:28

    Ciao SAVYBACK
    Non ho capito bene cosa vuoi ottenere dal codice... ma secondo il mio modesto parere
    per quello che vuoi ottenere hai provato ad utilizzare le funzioni di manipolazione delle stringhe???
    es. InStr()




  • di Grograman data: 30/08/2013 15:49:26

    Oppure, al posto della funzione "Instr" che restituisce un numero di tipo long pari alla posizione della stringa cercata , l'operatore "Like" che restituisce una booleana Vero/Falso:
     
    Sub insTroversa()
      Dim strA As String, strB As String
      Dim Chk As Variant, Chk2 As Variant
      
      strA = "trentatre trentini entrarono a trento tutti e trentattre trotterellando allegramente"
      strB = "tre"
      
      Chk = InStr(1, strA, strB, vbTextCompare)
      Debug.Print TypeName(Chk)
      
      If InStr(1, strA, strB, vbTextCompare) > 0 Then
        MsgBox "testo trovato"
      End If
      
      
      Chk2 = strA Like "*" & strB & "*"
      Debug.Print TypeName(Chk2)
      
      If strA Like "*" & strB & "*" Then
        MsgBox "testo trovato"
      End If
    
    End Sub
    



  • di Vecchio Frac data: 30/08/2013 18:46:07

    Bello così Gro', Like è un operatore che mi piace molto; hai scelto strA in mio onore? ^_^





  • di savyback (utente non iscritto) data: 30/08/2013 19:13:09

    Grazie ragazzi, ho risolto proprio con l'operatore "like"!!



  • di totygno71 (utente non iscritto) data: 30/08/2013 20:38:31

    Bene savy...
    allora spunta su risolto



  • di savyback (utente non iscritto) data: 31/08/2013 07:46:48

    Risolto, grazie!



  • di Grograman data: 31/08/2013 12:23:22

    cit: "hai scelto strA in mio onore? ^_^ "

    Ehhehe vorrei poterti sviolinare dicendo sì, ma non l'ho capita!!



  • di Vecchio Frac data: 31/08/2013 13:35:50

    LOL, bè io sono proprio di Trento (non te lo avevo già detto in privato? eh... l'età ^_^) e la variabile strA contiene la mia filastrocca locale :)





  • di Grograman data: 31/08/2013 15:28:53

    Ihihihi e se dicevo:

    "Orrore orrore ho visto un ramarro marrone rosicchiare un ratto arrosto a mururuoa"

    (se avete amici con la erre moscia fategliela dire, è uno spasso!)



  • di Vecchio Frac data: 31/08/2013 21:48:34

    cit. "(se avete amici con la erre moscia fategliela dire, è uno spasso!)"
    ---> Uh che perfido ^_^