Se connecter avec
S'enregistrer | Connectez-vous

Impossible de trouver l'objet dans la collection correspondant au nom

Dernière réponse : dans Programmation

Bonjour,

En ouvrant mon fichier Excel, j'obtiens une erreur :
  1. 3265
  2. 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 fonctionne très bien quand je la fais directement dans Oracle (par SQL+)

Voici la requête :

  1. strSQL = "select cote.indice, cote.cote_actuelle " & _
  2. "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" & _
  3. "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 très bien avec des requêtes simples):
  1. Set cN = New ADODB.Connection
  2. cN.ConnectionString = "Provider=msdaora;Data Source=OIU;User Id=XXXXX;Password=XXXX;"
Lassé par la pub ? Créez un compte

Meilleure solution


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 !

  1. strSQL = ""
  2. strSQL = strSQL & "select cote.indice indiceZ, "
  3. strSQL = strSQL & " cote.cote_actuelle coteZ"
  4. strSQL = strSQL & " from t_detail_vin pr, "
  5. strSQL = strSQL & " type_vin vin, "
  6. strSQL = strSQL & " (select ind.id_tvin, "
  7. strSQL = strSQL & " ind.milesime millesime, "
  8. strSQL = strSQL & " c.cote cote_actuelle, "
  9. strSQL = strSQL & " ind.id_indice indice "
  10. strSQL = strSQL & " from t_indices ind, "
  11. strSQL = strSQL & " cote_annuelle c "
  12. strSQL = strSQL & " where ind.id_indice = c.id_indice"
  13. strSQL = strSQL & " and ind.format in('Bouteille') "
  14. strSQL = strSQL & " and c.annee='2010' "
  15. strSQL = strSQL & " and ind.id_indice not in ('1','2','3') "
  16. strSQL = strSQL & " and ind.id_indice < '100') cote "
  17. strSQL = strSQL & " where vin.id_tvin = pr.id_tvin "
  18. strSQL = strSQL & " and pr.milesime = cote.millesime "
  19. strSQL = strSQL & " and vin.id_tvin=cote.id_tvin "
  20. strSQL = strSQL & " and vin.proprietaire not in ('Indifferent') "
  21. strSQL = strSQL & " and vin.proprietaire is not null "
  22. strSQL = strSQL & " order by cote.indice"
  23.  
  24. rs.Open strSQL, cN, adOpenForwardOnly, adLockOptimistic
  25.  
  26. If rs.RecordCount > 0 Then
  27.  
  28. j = 1
  29. i = 0
  30.  
  31. Do While Not rs.EOF And Not rs.BOF
  32.  
  33. i = i + 1
  34. Feuil1.Cells(i, j) = rs("coteZ")
  35. Feuil1.Cells(i, j + 1) = rs("coteZ")
  36. rs.MoveNext
Expert Programmation

Bonjour,

Fais un effort, écris correctement tes requêtes :
  1. ' // Requête
  2. select cote.indice,
  3. cote.cote_actuelle
  4. from t_detail_vin pr,
  5. type_vin vin,
  6. (select ind.id_tvin,
  7. ind.milesime millesime,
  8. c.cote cote_actuelle,
  9. ind.id_indice indice
  10. from t_indices ind,
  11. cote_annuelle c
  12. where ind.id_indice = c.id_indice
  13. and ind.format in ('Bouteille')
  14. and c.annee='2010'
  15. and ind.id_indice not in ('1','2','3')
  16. and ind.id_indice < '100') cote
  17. where vin.id_tvin = pr.id_tvin
  18. and pr.milesime = cote.millesime
  19. and vin.id_tvin = cote.id_tvin
  20. and vin.proprietaire not in ('Indifferent')
  21. and vin.proprietaire is not null
  22. order by cote.indice


Là, on voit bien mieux. Et on ne décèle aucune anomalie. [:spamafote]
Cherchons l'erreur ailleurs. Et si c'était dans ta façon d'écrire.

  1. strSQL = "sel...lle " & _
  2. "fro...ote" & _
  3. "whe...ice"

Ah, aaah ! Je vois là comme un problème. Il manquerait un espace.

Salut !

Sans l'espace entre "cote" et "where", on obtient l'erreur suivante à l'exécution :

ORA-00933: SQL command not properly ended

Si je met l'espace on obtient l'erreur décrite plus haut (petit oubli dans mon copier coller).
Je précise qu'à l'exécution, il n'y a aucune erreur.
C'est en ouvrant le fichier Excel que j'obtiens l'erreur 3265

Désolé pour la présentation de la requête...
Expert Programmation

Citation :
Désolé pour la présentation de la requête...
Eh, c'est pour toi, hein !

Attends, t'as une erreur sur la requête ou pas ?
Pourquoi tu nous en parles alors ?

C'est donc à l'ouverture de Excel que t'as tes problèmes.
C'est là qu'il faut chercher.

Ôte-moi d'un doute. Si tu mets
  1. strSQL = "SELECT 'hello, world' FROM DUAL "
dans ta requête, l'ouverture de ta feuille plante quand même ?
Lassé par la pub ? Créez un compte