Private Declare Function FindWindowA& Lib "user32" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function EnableWindow& Lib "user32" (ByVal hwnd&, ByVal bEnable&)
Private Declare Function GetWindowLongA& Lib "user32" (ByVal hwnd&, ByVal nIndex&)
Private Declare Function SetWindowLongA& Lib "user32" (ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&)
Option Compare Text
Option Explicit
Dim conn As Object 'pour connection base
Dim connstring 'pour connection base
Dim Rs As Object 'recordset
Dim Sql 'chaine requete SQL
Dim TInfos 'tableau recup requete SQL
Dim Flag_Nok As Boolean 'pas d'enregistrement
Dim NbRecord 'nombre d'enregistrement trouves
'connection base et recherche
Sub Connecte_base_Access()
Dim Rs As Object
Dim Nom_Base, Chemin_Base, Sql, PAPA, Admin, Uid, pwd, ExtendedAnsiSQL ', connstring
Set conn = CreateObject("ADODB.Connection")
' Nom_Base = "ListView table.accdb"
' Chemin_Base = ThisWorkbook.Path & "\" & Nom_Base
Chemin_Base = "C:\Users\mmmmmm\Documents\table.accdb"
connstring = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" & Chemin_Base & ";Uid=Admin;Pwd=mmmmm;ExtendedAnsiSQL=1;"
conn.Open connstring
End Sub
Sub Recherche_Infos_Affichage_LVW()
Dim Rs As Object
Dim DT1, DT2
Dim PartTxt, Sql, SQL1, n, L, c, D, e, NbF
On Error Resume Next
Set Rs = CreateObject("ADODB.recordset")
PartTxt = TextBox1
Sql = "select * from [parametreage] where [Nom et Prenom] like '%" & PartTxt & "%'"
Rs.Open Sql, conn, 3, 3
If Not Rs.EOF Then
Rs.MoveFirst
NbF = Rs.Fields.Count
NbRecord = Rs.RecordCount
n = 1
Do While Not Rs.EOF
With ListView1
.ListItems.Add , , Rs.Fields(0)
For L = 2 To NbF
.ListItems(n).ListSubItems.Add , , Rs.Fields(L - 1)
Next L
If .ListItems(n) = TextBox1 Then .ListItems(n).Bold = True
If .ListItems(n).ListSubItems(8).Text = "MMMMMMMMM" Then
.ListItems(n).Bold = True
.ListItems(n).ForeColor = vbRed
For c = 1 To .ColumnHeaders.Count - 1
.ListItems(n).ListSubItems(c).Bold = True
.ListItems(n).ListSubItems(c).ForeColor = vbRed 'couleur colonne 8
Next c
End If
End With
n = n + 1
Rs.MoveNext
Loop
Label2.Caption = NbRecord & " enregistrement(s) !"
Else
MsgBox "Attention: pas d'enregistrement trouvé!!"
End If
Rs.Close
Set Rs = Nothing
End Sub