OVH Cloud OVH Cloud

retourner un recordset

6 réponses
Avatar
Laurent M
Bonjour, j'ai une petite fonction VBA qui éxécute une requête SQL et qui
doit retourner le recordset correspondant.

Cependant je ne sais pas comment récupérer correctement le recordset

Ma fonction :

***************************************
Function ImportFromdb(Query As String)

Dim DBPath As String
Dim cnt As New ADODB.Connection
Dim Rst As New ADODB.Recordset

' chemin de la BDD
DBPath = "C:\Documents and
Settings\Administrateur\Bureau\MyPFE\financesoftWithData.mdb"

cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & DBPath & ";"

Rst.Open Query, cnt, adOpenStatic

ImportFromdb = Rst

Rst.Close: cnt.Close
Set Rst = Nothing: Set cnt = Nothing
Set Rg = Nothing
End Function
***************************************

partie de ma macro qui appelle la fonction :

Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT Name FROM INSTRUMENT")


J'ai une erreur d'incompatibilité de type.

Qu'est ce que ma fonction doit retourner précisément?

merci !

6 réponses

Avatar
Killedman
Bonjour,
la signature de ta fonction devrais ressembler à ceci

Function ImportFromdb(Query As String) as ADODB.Recordset
en espèrant que ça aide.
Avatar
Clément Marcotte
Des fois on se demande si tu lis les réponses.


"Laurent M" a écrit dans le
message de news:
Bonjour, j'ai une petite fonction VBA qui éxécute une requête SQL
et qui

doit retourner le recordset correspondant.

Cependant je ne sais pas comment récupérer correctement le recordset

Ma fonction :

***************************************
Function ImportFromdb(Query As String)

Dim DBPath As String
Dim cnt As New ADODB.Connection
Dim Rst As New ADODB.Recordset

' chemin de la BDD
DBPath = "C:Documents and
SettingsAdministrateurBureauMyPFEfinancesoftWithData.mdb"

cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
DBPath & ";"


Rst.Open Query, cnt, adOpenStatic

ImportFromdb = Rst

Rst.Close: cnt.Close
Set Rst = Nothing: Set cnt = Nothing
Set Rg = Nothing
End Function
***************************************

partie de ma macro qui appelle la fonction :

Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT Name FROM INSTRUMENT")


J'ai une erreur d'incompatibilité de type.

Qu'est ce que ma fonction doit retourner précisément?

merci !


Avatar
Clément Marcotte
22 janvier 2005, c'est pas si loin tabarnouche.

http://groups.google.com/groups?q=http:+group:microsoft.public.fr.excel+author:clement.marcotte%40sympatico.ca&hl=fr&lr=&scoring=d&selm=%23mDAU3JAFHA.1188%40tk2msftngp13.phx.gbl&rnum=3





"Laurent M" a écrit dans le
message de news:
Bonjour, j'ai une petite fonction VBA qui éxécute une requête SQL
et qui

doit retourner le recordset correspondant.

Cependant je ne sais pas comment récupérer correctement le recordset

Ma fonction :

***************************************
Function ImportFromdb(Query As String)

Dim DBPath As String
Dim cnt As New ADODB.Connection
Dim Rst As New ADODB.Recordset

' chemin de la BDD
DBPath = "C:Documents and
SettingsAdministrateurBureauMyPFEfinancesoftWithData.mdb"

cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
DBPath & ";"


Rst.Open Query, cnt, adOpenStatic

ImportFromdb = Rst

Rst.Close: cnt.Close
Set Rst = Nothing: Set cnt = Nothing
Set Rg = Nothing
End Function
***************************************

partie de ma macro qui appelle la fonction :

Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT Name FROM INSTRUMENT")


J'ai une erreur d'incompatibilité de type.

Qu'est ce que ma fonction doit retourner précisément?

merci !


Avatar
Clément Marcotte
Oupss! Pour toi ce n'était pas le 22 janvier, mais le 21 janvier. Mais
pour le reste...


http://groups.google.com/groups?hl=fr&lr=&threadm=eV3lmL9%24EHA.3236%40TK2MSFTNGP15.phx.gbl&rnum=4&prev=/groups%3Fhl%3Dfr%26lr%3D%26scoring%3Dd%26q%3Dhttp%253A%2Bgroup%253Amicrosoft.public.fr.excel%2Bauthor%253Aclement.marcotte%40sympatico.ca%26btnG%3DRechercher




"Clément Marcotte" a écrit dans le
message de news:
22 janvier 2005, c'est pas si loin tabarnouche.


http://groups.google.com/groups?q=http:+group:microsoft.public.fr.excel+author:clement.marcotte%40sympatico.ca&hl=fr&lr=&scoring=d&selm=%23mDAU3JAFHA.1188%40tk2msftngp13.phx.gbl&rnum=3






"Laurent M" a écrit dans le
message de
news:

Bonjour, j'ai une petite fonction VBA qui éxécute une requête SQL
et qui

doit retourner le recordset correspondant.

Cependant je ne sais pas comment récupérer correctement le
recordset



Ma fonction :

***************************************
Function ImportFromdb(Query As String)

Dim DBPath As String
Dim cnt As New ADODB.Connection
Dim Rst As New ADODB.Recordset

' chemin de la BDD
DBPath = "C:Documents and
SettingsAdministrateurBureauMyPFEfinancesoftWithData.mdb"

cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
DBPath & ";"


Rst.Open Query, cnt, adOpenStatic

ImportFromdb = Rst

Rst.Close: cnt.Close
Set Rst = Nothing: Set cnt = Nothing
Set Rg = Nothing
End Function
***************************************

partie de ma macro qui appelle la fonction :

Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT Name FROM INSTRUMENT")


J'ai une erreur d'incompatibilité de type.

Qu'est ce que ma fonction doit retourner précisément?

merci !





Avatar
Laurent M
ces articles ne m'aident pas à répondre à ma question...
Avatar
Clément Marcotte
Il y a des exemples d'utilisation d'un Recordset avec Excel. Donc,
c'est quoi la VRAIE QUESTION, pour faire quoi ? Me semble que la
répétition ad nauseam de la même question qui ne génère pas "les
bonnes réponses" n'est pas la bonne façon de procéder.


"Laurent M" a écrit dans le
message de news:
ces articles ne m'aident pas à répondre à ma question...