Erreur 424 Objet requis Macro Excel

Résolu
Gagou_c Messages postés 65 Date d'inscription mercredi 18 août 2004 Statut Membre Dernière intervention 31 janvier 2006 - 30 janv. 2006 à 11:18
chouchouk8917 Messages postés 1 Date d'inscription samedi 12 février 2011 Statut Membre Dernière intervention 8 mai 2012 - 8 mai 2012 à 20:35
Bonjour,

Je dois faire une macro avec excel qui consiste à parcourir une colonne, et pour chaque ligne trouver la référence correspondante dans une table de ma base ORACLE.

J'ouvre ma connexion, et lorsque j'exécute ma requete, il met l'erreur 424 "Objet Requis" sur une ligne de mon code ( rouge ci dessous ).
Je pense que le souci vient de la connexion passée en paramètre.

Pouvez vous m'aider ?

Merci

Voici mon code :

Sub Macro3()


' Connexion à la base


Dim connString As String
connString = "Provider=MSDAORA.1;Server=XXXX;Data Source=XXXXX;USER ID=XXXX;PASSWORD=XXXX"

'Création de l'objet connection
Set oConn = New ADODB.Connection
oConn.ConnectionString = connString

'Ouverture de la connexion
oConn.Open

'MsgBox "Connexion réussie"

For i = 1 To 2000

Cells(i, 1).Select

If Not IsNull(Cells(i, 1).Value) Then

Set rst = New ADODB.Recordset
Sql = "Select AVC from L3CGROUP.ITMFACILIT where ITMREF='" & Cells(i, 1).Value & "';"
rst.Open Sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

Cells(i, 2).Value = rst!AVC

Else
Cells(i, 2).Value = "Rien"
End If

Next

oConn.Close

End Sub

4 réponses

Gagou_c Messages postés 65 Date d'inscription mercredi 18 août 2004 Statut Membre Dernière intervention 31 janvier 2006
31 janv. 2006 à 08:29
Merci, jai réussi à le faire finalement !

Voici ma solution, plus complexe que la tienne :

Sub RequetePMP()


' Connexion à la base


Dim oConn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim cmdCommand As ADODB.Command

Dim connString As String

connString = "Provider=MSDAORA.1;Server=XXXX;Data Source=XXXX;USER ID=XXXX;PASSWORD=XXXX"

'Création de l'objet connection
Set oConn = New ADODB.Connection
oConn.ConnectionString = connString

'Ouverture de la connexion
oConn.Open

'MsgBox "Connexion réussie"

For i = 1 To 2000

Cells(i, 1).Select

If (Cells(i, 1).Value <> "") Then

Set cmdCommand = New ADODB.Command
Set cmdCommand.ActiveConnection = oConn
With cmdCommand
.CommandText = "Select AVC_0 from L3CGROUP.ITMMVT where ITMREF_0='" & Cells(i, 1).Value & "'"
.CommandType = adCmdText
'.Execute
End With

Set rst = New ADODB.Recordset
Set rst.ActiveConnection = oConn
'Sql = "Select AVC from L3CGROUP.ITMFACILIT where ITMREF='" & Cells(i, 1).Value & "';"
rst.Open cmdCommand

If rst.EOF = False Then
Cells(i, 4).Value = rst.Fields(0)
End If
Else
Cells(i, 4).Value = ""
End If

Set cmdCommand = Nothing
Set rst = Nothing

Next

oConn.Close

End Sub



Merci de ton aide !!!
3