![]() |
#1
|
|||
|
|||
![]()
Good day!
I'm using this macro: dim db as dao.database dim rst as dao.recordset set db = MyDB set rst=Mydb.OpenRecordset("MyRst") ...........et.c I frequently use this style but with different recordsets. Is it possible to create only one generic Sub and then pass certain values from other Sub? |
#2
|
||||
|
||||
![]()
Yes, it is possible. You need to work out what the variables are and then create a function with those variables as inputs and return the result. You will find lots of example functions on this forum.
If you need help with specific code, post all of that code and we can make suggestions on how you might do it.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
![]()
Dear Guessed,
Thanks for your reply. Below a sample of my requirements (with thanks): dim db as dao.database dim rst as dao.recordset set db = MYDB set rst=Mydb.OpenRecordset("MYRST") rst.index = "INDEX" if not rst.nomatch then rst.edit rst.FEILD1 = "abc" rst.FEILD2="xyz" rst.update All those in CAPS are the variables that change from one Sub to another Thanks again |
#4
|
||||
|
||||
![]()
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 |
#5
|
|||
|
|||
![]()
Thanks dear
|
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using the Filter function to dynamic search large table | le_robert | Excel | 3 | 06-27-2022 01:06 PM |
Hi, I wonder if I can make a dynamic document to speed up the creation of document | parisfranco | Word | 10 | 03-10-2022 01:20 PM |
![]() |
DKY | Mail Merge | 1 | 03-29-2020 04:43 PM |
![]() |
IanM_01 | Word | 5 | 11-21-2015 02:29 AM |
![]() |
lcaretto | Excel Programming | 2 | 05-26-2014 07:19 PM |