Results 1 to 8 of 8
  1. #1
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93

    Eliminate dead code


    Anyone know how to eliminate dead code without having to search line-by-line?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by thekruser View Post
    Anyone know how to eliminate dead code without having to search line-by-line?
    How would you know? Even if you searched line by line? Wouldn't you have to operate the program to know that?

    What do you mean by "dead code"?

    *Procedures that are in the VBE that are not linked to object events?
    *Actual code that's never used throughout?

    If you're talking about the first option, yes you could use the Extensibility library to search that and delete the code out that's not linked to objects.

  3. #3
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Dead code meaning code tied to cmdMyButton even though MyButton has been deleted.


    I am new to VBA, so I am not sure what the 'Extensibility library' is or where to find it. Can you explain?

    Thank you for your response!

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    if you're new to the language, you probably won't understand the ext. library at all. just being honest there.

    as far as code tied to controls and objects, all code is deleted automatically when the object or control is deleted, so you don't have to worrry about that type of code. The only exception to this (I think) is when you write code behind an EVENT and then only delete the "event procedure" words in the property sheet. It might be the other way around though, not sure.

    however, if you have code in a standard module such as:
    Code:
    forms("form").controls("cmdButton").enabled=false
    and that button has been deleted from the form, I would think it would be much trickier.

    The basic qualifying characters (the characters that separate qualifiers and their collections) is the period. the only way I know how to do this is to use the extensibility objects in vba to create a dynamic array and populate it with every code module object in the vba project. That's relatively easy (10 lines of code). The tough part would be parsing all of your code out based on the "." delimiter. You can read the lines one by one in every code module, but some code syntax that can relate to form controls (for example) can use the "!" qualifier instead of the ".":
    Code:
    forms!formname!control
    You would have to look at those as well. The other things to consider is locating the code that's relevant. It's MUCH easier if you have named entities in your database using conventional naming techniques (tblCustomers, frmCustomers, cmdButton). If you haven't, doing this would probably be impossible.

    Yes this is doable (and it would be a great way to clean up!), but to be honest with you, it might be a better idea to leave it be. I'm personally working with a FE file right now that could be 1MB smaller if I deleted all the code out that wasn't used!

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    another thing you might want to consider doing if you're concerned about broken references is to use the compiler. It will stop on all broken references in actual object code modules (the code behind forms and reports), but it won't in standard modules. You can use this method and the find/replace dialog in the VBE to quickly fix broken references, but I think you still might be stuck with the ones in modules and class modules.

  6. #6
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    If you're looking to delete entire Functions that are no longer bound to an existing Form or Report Object, then you can do that fairly easily. The process does require that you manually check every Form and Report in question though, so if you have experience with VBA, I would recommend you try implementing ajetrumpet's suggestion first.


    1. Open the Form or Report in question and switch to Design Mode.
    2. Open the Microsoft Visual Basic Editor by pressing [ALT]+[F11].
    3. Make sure you are browsing the "(General)" Object.
    4. Any Function that is listed in the Procedures List is a function that is not bound to a control. If any of these items are Events, they can most likely be be safely deleted.

    See the attached image for the location of the Object and Procedure Lists in the Visual Basic Editor.

  7. #7
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    @ajetrumpet: Thank you for the information. I have a mixture of dead code in my database. I am revamping from an older one of mine that I created before I knew what I was doing. Lots of issues with it.

    @Rawb: I used your method to get rid of a few lines. I was able to identify old code relatively quickly this way.

    Thank you both very much for your help!

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by thekruser View Post
    @ajetrumpet: Thank you for the information. I have a mixture of dead code in my database. I am revamping from an older one of mine that I created before I knew what I was doing. Lots of issues with it.

    @Rawb: I used your method to get rid of a few lines. I was able to identify old code relatively quickly this way.

    Thank you both very much for your help!
    Unfortunately, I doubt there is a tool out there to do what I described. There probably isn't a market for it. In this country, if there's a market for anything the product will be there (whether it's good or not) within the blink of an eye.

    Good luck with this. At least you've got some knowledge that you can work with now!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need code
    By Patience in forum Access
    Replies: 8
    Last Post: 07-01-2010, 07:26 AM
  2. Eliminate redundant data from Pick Box?
    By jsbdiver in forum Forms
    Replies: 5
    Last Post: 06-14-2010, 04:04 PM
  3. how to get to the raw code
    By YankeeImperialistDog in forum Programming
    Replies: 1
    Last Post: 03-05-2010, 01:55 PM
  4. Help with VBA code
    By bgonzal1 in forum Access
    Replies: 3
    Last Post: 12-14-2009, 07:12 AM
  5. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums