1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Public cnx As ADODB.Connection
Public recordset As ADODB.recordset
Sub ConnectDB(ByRef cnx As ADODB.Connection, ByVal strPath As String)
'Définition répertoire et chemin base
strPath = "c:\TRAITEMENT.mdb"
'Test si fichier accessible
If Len(Dir(strPath)) > 0 Then
Set cnx = New ADODB.Connection
If cnx.State <> adStateClosed Then cnx.Close
'Définition du pilote de connexion
cnx.Provider = "Microsoft.Jet.Oledb.4.0"
'Définition de la chaîne de connexion
cnx.ConnectionString = strPath
'Ouverture de la base de données
cnx.Open
Else
MsgBox "La base n'a pas pu être trouvée" & vbCrLf & _
strPath & vbCrLf & _
"n'est pas un chemin valide.", vbCritical + vbOKOnly
End If
End Sub
Public Sub QUALIF()
Connexion_BDD.ConnectDB cnx, strPath
Set recordset = New ADODB.recordset
recordset.CursorType = adOpenStatic
Dim dDateDéb, dDateFin As String
Dim dDatePériode As String
Dim data_recherchee As String
'data_recherchee = Sheets("Gestion BDD Nécrologie").rechercher_data_necro.Value
Vider_Liste_Qualif
dDateDéb = Sheets("QUALIFICATION").TextBox1.Value
dDateFin = Sheets("QUALIFICATION").TextBox2.Value
If IsDate(dDateDéb) Or IsDate(dDateFin) Then
Période = "([Date] BETWEEN #" + dDateDéb + "# And #" + dDateFin + "#)"
Else
Période = ""
End If
'récupération de la table Qualif
'If (detect_num(data_recherchee)) Then
recordset.Open ("SELECT * FROM T002_SAISIE_QUALIF WHERE " & Période & "ORDER BY Séquentiel;"), cnx ' ORDER BY Séquentiel"), cnx
i = [C_Sequentiel].Row + 1
While Not recordset.EOF
For j = 1 To recordset.Fields.Count
Sheets("QUALIFICATION").Cells(i, j) = recordset(j - 1)
Next
i = i + 1
recordset.MoveNext
Wend
'End If
End Sub |