Bonjour,
Dans la macro ci-dessous (merci Mercatog), on extrait des valeurs en testant le 1er caractère d'une chaîne. Ce n'est pas directement dans la requête sql mais avec "rst.MoveFirst" (je pense). Ou puis-je trouver des informations sur les instructions permettant d'extraire ce qu'on veut d'une chaîne de caractères (x caractères en partant de la gauche, de la droite, au milieu) en gardant cette macro ? (=pas de fonction left, right, stxt, ni instr....)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Sub RemplirDico(ByVal FichSce As String)
Dim sSQL As String, Client As String
Dim Cn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Dim i As Integer
 
'--- Connection ---
With Cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FichSce & ";Extended Properties=""Excel 12.0;HDR=YES;"""
    .Open
End With
 
'--- Définit la requête ---
sSQL = "SELECT * FROM [Feuil1$]"                 '/!\ Attention à ne pas oublier le symbole $ après le nom de la feuille.
Set Rst = Cn.Execute(sSQL)
If Not Rst.EOF Then
    Rst.MoveFirst
    Do While Not Rst.EOF
        Client = Rst(0).Value
        If Len(Client) > 0 Then
            Db = Db + 1
            If Not Dico.Exists(UCase(Client)) Then Dico.Add UCase(Client), Client
        End If
        Rst.MoveNext
    Loop
End If
Rst.Close
Set Rst = Nothing
Cn.Close
Set Cn = Nothing
End Sub