Recherche dans listbox en excel avec BDD Access

richi2casa

New Member
Joined
Feb 9, 2020
Messages
1
Office Version
  1. 2019
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
bonjour
vous pouvez m'aider pour trouver une solution car
j'ai bloque de faire une liaison avec listbox en excel et base donne Access pour la commande recherche ou filtre
merci

VBA Code:
       Private Sub Cmd_Afficher_Click()
Dim sqlrech As String 'sql
Dim Recset As Recordset
Dim gend As String
Dim table
'Call Reset_Form
Application.EnableCancelKey = xlDisabled
Application.DisplayAlerts = False
Application.ScreenUpdating = False

sqlrech = "Select * from tblEmployee where [Employee Name]  like  '%" & txtEmpID.Text & "%'"
'sqlrech = "SELECT * FROM tblEmployee WHERE [Employee Name]  Like '" & Me.txtEmpID.Text & " *' ORDER BY [Employee Prenom]"
Set Recset = New ADODB.Recordset

Recset.Open Source:=sqlrech, ActiveConnection:=nConnection, CursorType:=adOpenKeyset, LockType:=adLockOptimistic

' On s'assure qu'il y a des enregistrements à récupérer ...

If Recset.EOF Then
MsgBox "Aucun enregistrement !", vbExclamation
Else
With Recset
Usf_search.ListBox1.Clear
Usf_search.ListBox1.ColumnCount = 10
Usf_search.ListBox1.ColumnWidths = "40;60;60;60;60;60;60;60;60;160"
Usf_search.ListBox1.AddItem
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 0) = Recset.Fields("Employee ID").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = Recset.Fields("Employee Name").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = .Fields("Employee Prenom").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = Recset.Fields("DOB").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = Recset.Fields("Gender").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = Recset.Fields("Qualification").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = Recset.Fields("Mobile Number").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = Recset.Fields("Email ID").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = Recset.Fields("Address").Value
End With

End If

Recset.Close
Set Recset = Nothing

Application.DisplayAlerts = True
Application.ScreenUpdating = True
'   MsgBox " Les Données Soumises Avec Succès ! "
Exit Sub

ErrorHandler:

MsgBox Err.Description & " " & Err.Number, vbOKOnly + vbCritical, "Database Error"
Application.DisplayAlerts = True
Application.ScreenUpdating = True

'Ferme le jeu d'enregistrements s'il est toujours ouvert ...
nConnection.Close


End Sub
 
Last edited by a moderator:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,933
Messages
6,175,473
Members
452,646
Latest member
tudou

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top