ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert SQL query Sub to Function (https://www.excelbanter.com/excel-programming/329993-convert-sql-query-sub-function.html)

Steve[_77_]

Convert SQL query Sub to Function
 
I have a macro that queries an access database, and would like to turn
it into a user-defined function. The recordset that is returned should
always be one value only. I am stuck at this place in my code:

rst.Open SQLstr, conn
Range("C1").CopyFromRecordset rst

It works now, returning the value to Range("C1") on the worksheet. How
do I assign the query result to a function value? Thanks.


AA2e72E

Convert SQL query Sub to Function
 
either of these espressions will give you the value

rst.getstring

rst.fields(0).value

"Steve" wrote:

I have a macro that queries an access database, and would like to turn
it into a user-defined function. The recordset that is returned should
always be one value only. I am stuck at this place in my code:

rst.Open SQLstr, conn
Range("C1").CopyFromRecordset rst

It works now, returning the value to Range("C1") on the worksheet. How
do I assign the query result to a function value? Thanks.



Steve[_77_]

Convert SQL query Sub to Function
 
Beautiful, it works. Thanks.



All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com