B
BBert
Good evening (european time!), Excellers,
One of my user-defined functions connects to excel with ADO to retrieve
some data (from a closed file). Can I assign the retrieved recordset to
a variable for further editing in another sub? I get an error message at
the end of the function.
******************************
Function Get_The_Dates(sFile)
Dim sConnStr As String, sQuery As String, sAddress As String
Dim oRst As ADODB.Recordset
Dim oCon As ADODB.Connection
sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & sFile
& ";Extended Properties=Excel 8.0;"
sQuery = "SELECT * FROM [Sheet1$A9:B37]"
'Make Connection
Set oCon = New ADODB.Connection
oCon.Open sConnStr
'Retrieve the Data
Set oRst = New ADODB.Recordset
oRst.Open sQuery, oCon, adOpenForwardOnly, adLockReadOnly, adCmdText
Get_The_Dates = oRst
End Function
********************************
Another question I have is,
Can I use multiple ranges to compose the SELECT * FROM statement?
Something like
sQuery = "SELECT" & range("A1:B10") & "," & range("F1:G10") & " * FROM
[Sheet1$A1:J20]"
Thanks in advance,
Bert
One of my user-defined functions connects to excel with ADO to retrieve
some data (from a closed file). Can I assign the retrieved recordset to
a variable for further editing in another sub? I get an error message at
the end of the function.
******************************
Function Get_The_Dates(sFile)
Dim sConnStr As String, sQuery As String, sAddress As String
Dim oRst As ADODB.Recordset
Dim oCon As ADODB.Connection
sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & sFile
& ";Extended Properties=Excel 8.0;"
sQuery = "SELECT * FROM [Sheet1$A9:B37]"
'Make Connection
Set oCon = New ADODB.Connection
oCon.Open sConnStr
'Retrieve the Data
Set oRst = New ADODB.Recordset
oRst.Open sQuery, oCon, adOpenForwardOnly, adLockReadOnly, adCmdText
Get_The_Dates = oRst
End Function
********************************
Another question I have is,
Can I use multiple ranges to compose the SELECT * FROM statement?
Something like
sQuery = "SELECT" & range("A1:B10") & "," & range("F1:G10") & " * FROM
[Sheet1$A1:J20]"
Thanks in advance,
Bert