View Single Post
 
Old 04-13-2024, 09:06 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The point of using functions is that you can modularise a chunk of the code so you don't need to repeat that chunk inside your Sub or when creating new Subs. This doesn't save you from needing the code at all - it just allows you to be slightly more efficient in creating code.

It might make sense to create a function to return a Recordset. But what you choose to do with the recordset should probably be in the Sub itself since it will vary in a range of ways with each macro.

But the capability of that recordset function won't be a 'one size fits all'. For instance, what format is the database you are querying? Is it Excel, Access, ODBC etc. What is the filepath to that database? What is the name of the table inside that database that you want? Are you also passing a SQL string to specify which fields and records to include in the returned recordset. Is the answer to all these questions always the same? If not, the function will need those key bits of information in order to return the recordset you are expecting.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote