#1   Report Post  
Laurent M
 
Posts: n/a
Default return recordset

Hello, I have a little VBA function which execute a SQL
query. The function should return the relevant recordset.

But i get an error when i try to get the recordset from a
query :

My function :

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

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

' Database path
DBPath = "C:\Documents and
Settings\Administrateur\Bureau\MyPFE\financesoftWi thData.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
***************************************

here is the part of the sub which calls the function

Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT *FROM table")


So my question is : What should my function return precisely?

Thanks !
  #2   Report Post  
JulieD
 
Posts: n/a
Default

Hi

not sure if it's an issue but there doesn't appear to be a space between the
* and the FROM

Cheers
JulieD

"Laurent M" wrote in message
...
Hello, I have a little VBA function which execute a SQL
query. The function should return the relevant recordset.

But i get an error when i try to get the recordset from a
query :

My function :

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

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

' Database path
DBPath = "C:\Documents and
Settings\Administrateur\Bureau\MyPFE\financesoftWi thData.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
***************************************

here is the part of the sub which calls the function

Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT *FROM table")


So my question is : What should my function return precisely?

Thanks !



  #3   Report Post  
 
Posts: n/a
Default

i miss typed the query ;)
but i test to use data directly in the function
ImportFromdb and it works perfectly

the error comes from the return thing.


-----Original Message-----
Hi

not sure if it's an issue but there doesn't appear to be a

space between the
* and the FROM

Cheers
JulieD

  #4   Report Post  
Laurent M
 
Posts: n/a
Default

seems my last message doesn't appear

i just miss typed my query. ;)
in fact i tested to display data directly in the function
ImportFromdb and it works perfectly.

the error comes from the return.




-----Original Message-----
Hi

not sure if it's an issue but there doesn't appear to be a

space between the
* and the FROM

Cheers
JulieD

"Laurent M" wrote in

message
...
Hello, I have a little VBA function which execute a SQL
query. The function should return the relevant recordset.

But i get an error when i try to get the recordset from a
query :

My function :

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

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

' Database path
DBPath = "C:\Documents and

Settings\Administrateur\Bureau\MyPFE\financesoftWi thData.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
***************************************

here is the part of the sub which calls the function

Dim Rst As New ADODB.Recordset
Set Rst = ImportFromdb("SELECT *FROM table")


So my question is : What should my function return

precisely?

Thanks !



.

  #5   Report Post  
Jamie Collins
 
Posts: n/a
Default

Laurent M wrote:
the error comes from the return.


Try

Set ImportFromdb = Rst

You could also change the declaration to

Function ImportFromdb(Query As String) As ADODB.Recordset
Jamie.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula to return cell contents based on multiple conditions Bill Excel Worksheet Functions 3 January 19th 05 09:59 AM
Can VLOOKUP return multiple answers based on several identical lo. jddtct Excel Worksheet Functions 3 January 11th 05 07:03 AM
Return the smallest value Donkey Excel Worksheet Functions 2 December 24th 04 10:10 PM
Carriage Return in Excel Rod Behr Excel Discussion (Misc queries) 4 December 14th 04 01:53 PM
Return the end of month date from a date Steve F. Excel Worksheet Functions 3 October 28th 04 06:17 PM


All times are GMT +1. The time now is 03:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"