Results 1 to 6 of 6
  1. #1
    drunyan0824 is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2022
    Posts
    82

    Best way to remove extraneous code from Access

    When I was last working on my database for cable and equipment tracking, I simply tired to add some break point in my code to troubleshoot an issue and the database crashed. The file closed and I got an error message that Access couldn't compact the database and there was a new file with the name Database.mdb and my original database was locked and only 1 kb in size. Luckily I had a back up so I just lost my work from yesterday which wasn't a whole lot. However it got me thinking about my database and finally admit to myself that some of the buttons and things that I have created are extremely unnecessary. Mostly, the command buttons that I programed for Saving, navigation through records and having very similar search functions on different forms. Also possible more queries than I need.

    Granted, I am not sure if any of that is related to why the database crashed so bad, but I figure it can't make anything worse by removing the extra coding that is not needed. I know that access can be kind of weird in the way that things are deleted and I am just wondering if there is a best practice for deleting code. If I delete a command button from a form will that also delete the code or should I delete the code and then delete the command button? Or does it matter?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    I tend to comment out any code that appears to be no longer needed.
    After a set period of time, if no issues, then the next time I am editing I might remove it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Agree with that idea. To answer the question directly, remove button, code stays. Remove code, button stays. The order of removals would not matter.
    We'll likely never know what caused the crash. Certainly should not have been using break points.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    I would remove the code first, locating each code procedure by clicking the events in the property sheet.
    There could be orphan code blocks remaining because of buttons deleted in the past. Use WGM's method to deal with those.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by drunyan0824 View Post
    .. my original database was locked and only 1 kb in size.
    That was the lock file created when any database is opened


    A quick way of identifying orphaned code in form/report class modules is to look at the right hand Declarations dropdown in the VBE.

    Click image for larger version. 

Name:	CaptureVBE.PNG 
Views:	16 
Size:	139.2 KB 
ID:	50204

    This lists all the subs/functions for that module.
    However any items that reference control events are orphaned and can safely be deleted
    Last edited by isladogs; 05-05-2023 at 05:56 AM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    twgonder is online now Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    652
    I have, and asked in this forum, about the exact type of crash you experienced.
    (Although I change the code, add break-points, save, modify a form or report, etc. to get the crashes happen, so I wouldn't count on it being just the breakpoint, as my crashes can start happening several minutes after something seemed to run okey.)
    I'm doing a lot of coding, so it happens on an almost daily basis.

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

Similar Threads

  1. Remove Duplicate VBA code not working
    By jyellis in forum Programming
    Replies: 3
    Last Post: 02-08-2018, 05:54 PM
  2. Replies: 1
    Last Post: 01-24-2017, 01:05 PM
  3. Combo-Box Lookup Finding Extraneous Values
    By jmitchelldueck in forum Forms
    Replies: 10
    Last Post: 12-17-2015, 02:29 PM
  4. Want to remove duplicates from a SQL code
    By Huddle in forum Access
    Replies: 1
    Last Post: 12-31-2013, 03:11 PM
  5. Extraneous character in Concatenation
    By bruegel in forum Queries
    Replies: 8
    Last Post: 07-23-2012, 10:14 AM

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