Userform 2 dans multipage1 avec moteur de recherche pour afficher liste

Bonsoir,

j'ai un userform2 qui est dans le multipage 1

dans ce multipage 1 il y a la combobox2 pour la liste déroulante ou, en tapant les 2ers caracteres dans la textbox25 qui devraient lister les noms ( les noms dans la base de données sont nommés aussi "LNom") dont la source est dans la feuille4 "BASE DE DONNEES" ,

et enfin la listBox1 qui devrait donc montrer de la Colonne A à T et la colonne X tout ce qui se réfère à la personne sélectionnée (Nom)

mais rien ne marche, alors que si je fais recherche fiche par N° de Dossier ça marche

je joins un fichier exemple pour mieux me faire comprendre

merci d'avance pour votre aide et votre patience !

Bonjour

Ci joint ma solution… Je te laisse finir (je n'ai rempli que la valeur des 12 premières colonnes)

A+ François

déjà, un énorme merci pour le temps consacré !

alors quand je l'ai adapté à mon vrai formulaire, j'ai eu un soucis,

Les combobox ne s'alimentaient pas alors que sur votre exemple ça marchait parfaitement.

pour résoudre cela j'ai rajouté une liste "LDossier" qui est la rowsource de la combo1

et une liste "LNom"qui est la rowsource de la combo2

le résultat s'affiche alors dans la listbox

par contre je n'arrive pas à avoir les entêtes, malgré ColumnsHeads sur True et dans le code que je joins ci-après

1- comment résoudre ça ?

2- savez vous comment faire apparaître le nombre total de valeurs trouvées (dans une listbox2)?

merci d'avance pour votre aide.

je joins le code au cas où j'aurais fait une bêtise....

Option Explicit

Private Sub ComboBox1_Change()
  If Me.ComboBox1.ListIndex = -1 Then Exit Sub
  affdonnees (Me.ComboBox1.ListIndex + 2)
End Sub

Private Sub ComboBox2_Change()
  Dim lig As Long, dl As Long, firstaddr As String, c As Range, i As Long
  dl = [T_Data].Rows.Count
  If Len(ComboBox2.Value) = 0 Then Exit Sub
  Application.ScreenUpdating = False
  Me.ListBox1.Clear
  Me.ListBox1.ColumnWidths = "0;80;20;80;80;80;80;80"
  Me.ListBox1.ColumnHeads = True
  Set c = Range("T_Data").Columns(6).Find("*" & Me.ComboBox2.Value & "*")
  If Not c Is Nothing Then
    firstaddr = c.Address
  End If
  Do Until c Is Nothing
    Me.ListBox1.AddItem c.Row - 1
    Me.ListBox1.List(ListBox1.ListCount - 1, 1) = Cells(c.Row, 1) 'Dossier
    Me.ListBox1.List(ListBox1.ListCount - 1, 2) = Cells(c.Row, 5) 'Civilité
    Me.ListBox1.List(ListBox1.ListCount - 1, 3) = Cells(c.Row, 6)  'Nom
    Me.ListBox1.List(ListBox1.ListCount - 1, 4) = Cells(c.Row, 7)  'Prénom
    Me.ListBox1.List(ListBox1.ListCount - 1, 5) = Format(Cells(c.Row, 10), "00 00 00 00 00") 'Téléphone fixe
    Me.ListBox1.List(ListBox1.ListCount - 1, 6) = Format(Cells(c.Row, 11), "00 00 00 00 00")  'Portable
    Me.ListBox1.List(ListBox1.ListCount - 1, 7) = Cells(c.Row, 12) 'Mail
    Set c = Range("T_Data").Columns(6).FindNext(after:=c)
    If c.Address = firstaddr Then
        Exit Do
    End If
  Loop
  Application.ScreenUpdating = True
End Sub

Private Sub CommandButton5_Click()

End Sub

Private Sub ListBox1_Click()
 With Me.ListBox1
   ' MsgBox .List(.ListIndex, 0)'pour afficher la valeur sélectionnée de la colonne1
    Range(Me.ListBox1.RowSource).Rows(.ListIndex + 5).Select  '<<<================== 'Listindex commençant à zéro
    Me.ListBox1.ColumnHeads = True
End With
affdonnees (Me.ListBox1.Value + 1)
End Sub

Private Sub MultiPage1_Change()

End Sub

Private Sub TextBox25_Change()
  Dim lig As Long, dl As Long, firstaddr As String, c As Range, i As Long
  dl = [T_Data].Rows.Count
  If Len(TextBox25.Value) = 0 Then Exit Sub
  Application.ScreenUpdating = False
  Me.ListBox1.Clear
  ListBox1.ColumnHeads = True
  Me.ListBox1.ColumnWidths = "0;80;20;80;80;80;80;80"
  Set c = Range("T_Data").Columns(6).Find("*" & Me.TextBox25.Value & "*")
  If Not c Is Nothing Then
    firstaddr = c.Address
  End If
  Do Until c Is Nothing
    Me.ListBox1.AddItem c.Row - 1
    ListBox1.ColumnHeads = True
    Me.ListBox1.List(ListBox1.ListCount - 1, 1) = Cells(c.Row, 1) 'Dossier
    Me.ListBox1.List(ListBox1.ListCount - 1, 2) = Cells(c.Row, 5) 'Civilité
    Me.ListBox1.List(ListBox1.ListCount - 1, 3) = Cells(c.Row, 6)  'Nom
    Me.ListBox1.List(ListBox1.ListCount - 1, 4) = Cells(c.Row, 7)  'Prénom
    Me.ListBox1.List(ListBox1.ListCount - 1, 5) = Format(Cells(c.Row, 10), "00 00 00 00 00") 'Téléphone Fixe
    Me.ListBox1.List(ListBox1.ListCount - 1, 6) = Format(Cells(c.Row, 11), "00 00 00 00 00") 'Portable
    Me.ListBox1.List(ListBox1.ListCount - 1, 7) = Cells(c.Row, 12) 'Mail
    Set c = Range("T_Data").Columns(6).FindNext(after:=c)
    If c.Address = firstaddr Then
        Exit Do
    End If
  Loop
  Application.ScreenUpdating = True
End Sub

Private Sub UserForm2_Initialize()
ListBox.ColumnHeads = True
 Me.ComboBox1.RowSource = WsBD.[T_Data[Dossier]].Address(External:=True)
  Me.ComboBox2.RowSource = WsBD.[T_Data[Nom ]].Address(External:=True)
  Me.ComboBox1.ListIndex = -1: Me.ComboBox2.ListIndex = -1
End Sub

Sub affdonnees(lig)
  Dim i As Integer
  For i = 1 To 12
    If i > 9 And i < 12 Then
      Me.Controls("Textbox" & i).Value = Format(Sheets("BASE DE DONNEES").Cells(lig, i).Value, "00 00 00 00 00")
    Else
      Me.Controls("Textbox" & i).Value = Sheets("BASE DE DONNEES").Cells(lig, i).Value
    End If
  Next
  Me.MultiPage1.Value = 0
End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

End Sub

Bonjour

Pour avoir les entêtes d'un lisbox il faut qu'il soit alimenter par rowsource (impossible dans notre cas)

pour afficher la quantité trouvé dans un textbox ou un label utilise : Me.ListBox1.ListCount

A+ François

Rechercher des sujets similaires à "userform multipage1 moteur recherche afficher liste"