[Excel 2003] VBA et requête SQL

ajor

XLDnaute Nouveau
Bonjour,


En ouvrant mon fichier Excel, j'obtiens une erreur :

Code:
3265
Impossible de trouver l'objet dans la collection correspondant au nom ou à la référence ordinale demandé

Le code contient une requête SQL qui pourtant fonctionne très bien quand je la fais directement dans Oracle (par SQL+)

Voici la requête :

Code:
strSQL = "select cote.indice, cote.cote_actuelle " & _
                "from t_detail_vin pr, type_vin vin, (select ind.id_tvin,ind.milesime millesime,c.cote cote_actuelle, ind.id_indice indice from t_indices ind,cote_annuelle c where ind.id_indice = c.id_indice and   ind.format in('Bouteille') and  c.annee='2010' and ind.id_indice not in ('1','2','3') and ind.id_indice < '100') cote " & _
                "where vin.id_tvin = pr.id_tvin and pr.milesime = cote.millesime and vin.id_tvin=cote.id_tvin and vin.proprietaire not in ('Indifferent') and vin.proprietaire is not null order by cote.indice"


A votre avis, d'où vient l'erreur ?

Précision : je travaille sur Excel 2003, j'appelle une base Oracle 10g avec cette fonction (qui fonctionne bien avec des requêtes simples):

Code:
Set cN = New ADODB.Connection
    cN.ConnectionString = "Provider=msdaora;Data Source=OIU;User Id=XXXXX;Password=XXXX;"

2eme précision :
Il n'y a pas d'erreur à l'execution dans le "Visual BAsic Editeur". Cela semble compiler correctement. L'erreur apparait à l'ouverture du ficher xls.
 

ajor

XLDnaute Nouveau
Re : [Excel 2003] VBA et requête SQL

C'est bon, j'ai trouvé !

Si ça intéresse d'autres personne, voici le soucis :
Excel n'aime pas les points dans les variables (comme "cote.indice"...)
Du coup, j'ai mis un alias, et maintenant ça fonctionne !

Code:
strSQL = ""
strSQL = strSQL & "select cote.indice indiceZ, "
strSQL = strSQL & "       cote.cote_actuelle coteZ"
strSQL = strSQL & "  from t_detail_vin pr, "
strSQL = strSQL & "       type_vin vin, "
strSQL = strSQL & "      (select ind.id_tvin, "
strSQL = strSQL & "              ind.milesime millesime, "
strSQL = strSQL & "              c.cote cote_actuelle, "
strSQL = strSQL & "              ind.id_indice indice "
strSQL = strSQL & "         from t_indices ind, "
strSQL = strSQL & "              cote_annuelle c "
strSQL = strSQL & "        where ind.id_indice = c.id_indice"
strSQL = strSQL & "          and ind.format in('Bouteille') "
strSQL = strSQL & "          and c.annee='2010' "
strSQL = strSQL & "          and ind.id_indice not in ('1','2','3') "
strSQL = strSQL & "          and ind.id_indice < '100') cote "
strSQL = strSQL & "  where vin.id_tvin = pr.id_tvin "
strSQL = strSQL & "    and pr.milesime = cote.millesime "
strSQL = strSQL & "    and vin.id_tvin=cote.id_tvin "
strSQL = strSQL & "    and vin.proprietaire not in ('Indifferent') "
strSQL = strSQL & "    and vin.proprietaire is not null "
strSQL = strSQL & "  order by cote.indice"
 
      rs.Open strSQL, cN, adOpenForwardOnly, adLockOptimistic
        
        If rs.RecordCount > 0 Then
        
            j = 1
            i = 0
            
          Do While Not rs.EOF And Not rs.BOF
                
    i = i + 1
    Feuil1.Cells(i, j) = rs("coteZ")
    Feuil1.Cells(i, j + 1) = rs("coteZ")
    rs.MoveNext
 

Statistiques des forums

Discussions
311 729
Messages
2 081 970
Membres
101 852
dernier inscrit
dthi16088