Go Back   Access World Forums > Microsoft Access Reference > Code Repository

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 11-19-2015, 04:31 AM   #1
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,769
Thanks: 55
Thanked 1,022 Times in 988 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Compare 2 Code Modules

I just had a situation where I wanted to check whether code had been changed in two versions of a form. It's a pain doing it by inspection - so I put together this little code snippet.

a) It doesn't check that both forms exist.
b) when it finds a difference it shows 100 characters before and after the difference, and I haven't tried to debug this for bof/eof.
c) easy to modify to check reports.
d) probably can be used to check 2 modules.
e) 1 catch. save changes before running this. I think running the code drops any unsaved edits


Code:
 
 Sub compare2forms()
Dim frm1 As String
Dim frm2 As String
 Dim strg1 As String
Dim strg2 As String
 Dim x As Long
Dim ch1 As String
Dim ch2 As String
  
     frm1 = "testform1"
    frm2 = "testform2"
    
checkit:
    strg1 = getcodefrm(frm1)
    strg2 = getcodefrm(frm2)
    
    If strg1 = strg2 Then
        MsgBox ("Compared forms: " & vbCrLf & vbCrLf & _
            frm2 & vbCrLf & _
            frm1 & vbCrLf & vbCrLf & _
            "code is the same")
    Else
 'compare code, a character at a time, and report first difference
        x = 1
nextch:
        ch1 = Mid(strg1, x, 1)
        ch2 = Mid(strg2, x, 1)
        If ch1 <> ch2 Then
            MsgBox ("Compared forms: " & vbCrLf & vbCrLf & _
                frm2 & vbCrLf & _
                frm1 & vbCrLf & vbCrLf & _
                "code different at char " & x & vbCrLf & _
                Mid(strg1, x - 100, 200))
        Else
            x = x + 1
            GoTo nextch
        End If
    End If
    
 End Sub
  
  
 Function getcodefrm(fname As String) As String
  
 'get the code from the forms module
Dim x As Long
Dim lines As Long
Dim strg As String
  
     DoCmd.OpenForm fname, acDesign
    If Forms(fname).HasModule Then
        lines = Forms(fname).Module.CountOfLines
        strg = Forms(fname).Module.lines(1, lines)
        getcodefrm = strg
    End If
     DoCmd.Close acForm, fname, acSaveNo
End Function

__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the bottom left of this posting, or use the thanks button alongside.

Last edited by gemma-the-husky; 11-20-2015 at 05:54 AM.
gemma-the-husky is offline  
Old 11-19-2015, 08:18 AM   #2
RuralGuy
AWF VIP
 
RuralGuy's Avatar
 
Join Date: Jul 2005
Location: @ 8300' in the Colorado Rockies
Posts: 13,820
Thanks: 7
Thanked 311 Times in 301 Posts
RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice
Re: Compare 2 Code Modules

Thanks Dave. It will give us something to play with.
__________________
(RG for short) aka Allan Bunch Previous MS Access MVP acXP, ac07, ac10, ac13 - WinXP Pro, Win7 Pro, Win10 Pro
Please post back to this Forum so all may benefit.
Teaching is not filling a bucket but lighting a fire.
RuralGuy is offline  
Closed Thread

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Hiding VBA code/tables/modules tmcrouse Forms 1 07-18-2014 11:30 AM
[SOLVED] Converting Macros to Code/Modules Mike375 Modules & VBA 5 01-09-2008 06:59 AM
documenting vba code, modules, etc in Access greaseman General 2 10-14-2005 03:41 AM
Using Modules to Neaten My Code... saross Modules & VBA 2 10-22-2004 12:32 AM
Code Modules dsmaj General 1 05-12-2004 12:33 PM




All times are GMT -8. The time now is 10:15 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World