Link to home
Start Free TrialLog in
Avatar of Conernesto
ConernestoFlag for United States of America

asked on

Access VBA - Is there a way to tell when code was changed or if it hasn't been changed?

I am trying to find if there were any changes on some of my code from my 2015 database to my 2016 database. Or if I can tell based on a system date the last date code was modified. Is there a date/time option that can be used to track code changes?

Is there a way to tell the last date VBA code was changed?

Conernesto
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

start with this code

   Dim db As Database
    Dim C As Container
   
    Set db = CurrentDb()
    Set C = db.Containers("Modules")
    For Each d In C.Documents
        Debug.Print d.Name, d.DateCreated, d.LastUpdated
    Next d
Avatar of Conernesto

ASKER

Is a name needed for the code you sent me? Please volunteer a name if needed.
d.Name - will display the name of the module.
I entered the code per below. When I run the code I get asked for a name. What am I doing wrong?

Option Compare Database

   Dim db As Database
     Dim C As Container
     
     Set db = CurrentDb()
     Set C = db.Containers("Modules")
     For Each d In C.Documents
         Debug.Print d.Name, d.DateCreated, d.LastUpdated
    Next d

End Sub
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am getting a compile error. Variable not defined and it's looking at    For Each d
open your references and look for MISSING
uncheck and look for the available similar reference

do a Compact and repair
do a Debug >Compile
see which line will be highlighted for errors
The line that is highlighted in yellow is "Sub getModuleStatus ()". I don't see anything missing in reference.
where did you place the codes?
you should put it in a regular module so you can run it for testing by clicking on the  run icon from the vba window
I created a new module. Do need to put the code in an existing Form? If yes where do I copy the code before the end?
Do I copy the code to existing Code?
Avatar of Norie
Norie

Add this alongside the other declarations.
Dim d As Object

Open in new window

Note I've used Object as I'm not 100% sure how d should be typed, probably as Document, or DAO.Document, at a guess.
I added the line of code Dim d As Object. When I run the code nothing happens.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh, yeah this line
7:      Dim d As Document

was omitted in my codes above.
Great, I can see the dates when I open the Immediate Window (Ctrl+G). I am not sure how to enter getModuleStatus in the window to print the information.
just placed the cursor inside the SUB and click Run (right arrow) from the Tool bar
I can see the date created and date modified for each module. However the dates created and modified are the same for in each different module.  see two examples below.

ModuleA   11/18/2016  11:27:30 AM   11/18/2016  11:27:30 AM
ModuleB   12/23/2014 1:54:15 PM      12/23/2014 1:54:15 PM
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My goal was to prove that no code changes had been done from a year ago.
or to identify modules that had changes from an earlier database. For example my 2015 database vs my 2016 database.