Which modules are needed (1 Viewer)

Catalina

Registered User.
Local time
Today, 12:47
Joined
Feb 9, 2005
Messages
462
I have an application that is several years old, it needs some updates and slimming down. I want to weed out everything that is not needed.

My idea is to create a new one and only import tables, form, reports etc. that are needed from the old database.

But what is the best way to determine which modules are needed? I'm sure there are some that I can purge.

My idea is to go into the old application, see where a module is called and find the right one by using the find function in the VBA editor.

Does that make any sense at all? Or is there a better way to do this?

All suggestions will be appreciated.
 

Ranman256

Well-known member
Local time
Today, 15:47
Joined
Apr 9, 2015
Messages
4,337
no need to do it at all. It would only break something. Leave them. Text does not take up room.
Internal Tables take up room. compact regularly.
 

sonic8

AWF VIP
Local time
Today, 21:47
Joined
Oct 27, 2015
Messages
998
no need to do it at all. It would only break something. Leave them. Text does not take up room.
Code is a liability. It consumes the attention and time of the maintainer. It makes perfect sense to purge old code that is no longer needed.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:47
Joined
Feb 19, 2002
Messages
43,297
It makes perfect sense to purge old code that is no longer needed
You need to do this as you are coding. There is no benefit to keeping unused code. If you are unsure about whether you might need pieces of code later, comment them out at least. That allows you to identify them later and delete them or copy them into an old code locker for future use.

Now, start by commenting out all the code of a module. Complie. Put back what causes a failure. I'm assuming you use Option Explicit because if you don't, you have to fix that first and fix all compile errors.
 

ebs17

Well-known member
Local time
Today, 21:47
Joined
Feb 7, 2020
Messages
1,949
All suggestions will be appreciated.
Are you reasonably fit in programming?

When dealing with procedures instead of whole modules:
Registration of the names of the procedures
List all procedures of a module
List all procedures

With the SaveAsText method you can export the complete definitions of all Access objects (forms, reports, macros, modules) to text files.
You can now use a loop to search for the procedure names in the individual text files and note any hits.
Overall, this is probably a bit more structured than a manual search or commenting out and waiting for the resulting errors.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 20:47
Joined
Jan 14, 2017
Messages
18,239
I'd also suggest sorting out your code and indeed other database objects.
You can use Object Dependencies to identify orphan forms, reports, queries and tables
However, that doesn't work for modules.

The following assumes you have Option Explicit on all code modules.

1. Compile your project.
2. Open a module and comment out all the code. Recompile. If it compiles OK, nothing is that module is needed.
If it doesn't compile, restore the procedures that are still used.
3. Repeat in turn with each module.

OR import all objects except modules into a new database. Try to compile and when it fails import what you need.

Which method will be less work will depend on how much redundant code you have.
Much better to keep your project up to date so this situation doesn't arise again in future

OR use a utility such as V-Tools or Find and Replace by Access DevTools or the Dependency Checker addin tool
 

Josef P.

Well-known member
Local time
Today, 21:47
Joined
Feb 2, 2023
Messages
827
Within the code modules the dependencies of the procedures can also be checked with RubberDuck.
To supplement would be possibly still functions which are used e.g. directly in a ControlSource.

... import all objects except modules into a new database. Try to compile and when it fails import what you need.
If this is perhaps also combined with refactoring at the same time, the boy scouts will be happy. ;)
 

GPGeorge

Grover Park George
Local time
Today, 12:47
Joined
Nov 25, 2004
Messages
1,876
MZ Tools includes a "Dead Code Review" which finds unused, or dead, procedures.
1688760508182.png
 

Josef P.

Well-known member
Local time
Today, 21:47
Joined
Feb 2, 2023
Messages
827
Note: Mz-Tools only lists private procedures in this check, which are not used.
 

GPGeorge

Grover Park George
Local time
Today, 12:47
Joined
Nov 25, 2004
Messages
1,876
Note: Mz-Tools only lists private procedures in this check, which are not used.
Interesting. I had never noticed that it only found dead code in private procedures.

It's also true that it would ONLY find dead code in VBA, not control sources, etc.
 

GPGeorge

Grover Park George
Local time
Today, 12:47
Joined
Nov 25, 2004
Messages
1,876
Interesting. I had never noticed that it only found dead code in private procedures.

It's also true that it would ONLY find dead code in VBA, not control sources, etc.
1688772460799.png
 

Josef P.

Well-known member
Local time
Today, 21:47
Joined
Feb 2, 2023
Messages
827
I had never noticed that it only found dead code in private procedures.
In private scope.

See MZ-Tools options:
Mz-Tools-Options-DeadCode.png


=> find dead code inside procedures, private module variables, ...
But the use of public variables and public procedures is not checked.
 

isladogs

MVP / VIP
Local time
Today, 20:47
Joined
Jan 14, 2017
Messages
18,239
That makes sense. It would take ages to check all the code for every public sub / function

Thanks for the reminder about using MZTools for this
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:47
Joined
Sep 12, 2006
Messages
15,658
Personally I think with a big DBS you are more likely to duplicate a query or a function, because of the difficulty in keeping track of

Also if a DBS is working well, it's hardly worth the time trying to identify code that could be removed or improved. Often it's just easier to get on with the next project.

Re-engineering apps is difficult for much the same reason. It can be easier to start over.
 
Last edited:

GPGeorge

Grover Park George
Local time
Today, 12:47
Joined
Nov 25, 2004
Messages
1,876
In private scope.

See MZ-Tools options:
View attachment 108743

=> find dead code inside procedures, private module variables, ...
But the use of public variables and public procedures is not checked.
Thanks for pointing that out. I've been relying on my own brand of "misinformation" about dead code.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:47
Joined
Sep 12, 2006
Messages
15,658
@GPGeorge out of interest, what did you do with Northwind V2? Did you start over, or reuse parts of the existing?
 

GPGeorge

Grover Park George
Local time
Today, 12:47
Joined
Nov 25, 2004
Messages
1,876
Seriously, I joined the project after it was underway, so I wasn't part of the initial design discussions.

That said, pretty much every aspect of the application was reviewed and evaluated. There are significant resemblances, obviously. Northwind has an inventory of products which it sells to customers and employees who sell them. Those conceptual things don't really change, although the architecture was recreated.
 

Users who are viewing this thread

Top Bottom