I have an Access DB that I would like to extract the source code from so I can put it into Source control.
I have tried to extract the data using the Primary Interop Assemblies(PIA), but I am getting issues as it is not picking up all of the modules and forms.
There are 140 Forms and Modules in the code(Don't ask, it's a legacy system I have inherited) but the PIA code is only picking up 91 of them.
Here is the code I am using.
using System;
using Microsoft.Office.Interop.Access;
namespace GetAccesSourceFiles
{
class Program
{
static void Main(string[] args)
{
ApplicationClass appClass = new ApplicationClass();
try
{
appClass.OpenCurrentDatabase("C:\\svn\\projects\\db.mdb",false,"");
Console.WriteLine(appClass.Version);
Console.WriteLine(appClass.Modules.Count.ToString());
Console.WriteLine(appClass.Modules.Parent.ToString());
int NumOfLines = 0;
for (int i = 0; i < appClass.Modules.Count; i++)
{
Console.WriteLine(appClass.Modules[i].Name + " : " + appClass.Modules[i].CountOfLines);
NumOfLines += appClass.Modules[i].CountOfLines;
}
Console.WriteLine("Number of Lines : " + NumOfLines);
Console.ReadKey();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + "\r\n" +ex.StackTrace);
}
finally
{
appClass.CloseCurrentDatabase();
appClass.Quit(AcQuitOption.acQuitSaveNone);
}
}
}
}
Any suggestions on what that code might be missing? or on a product/tool out there that will do this for me?
Edit: I should also mention that this needs to script to disk, integration with VSS is not an option as our source system is SVN. Thanks.
There is a better way. You can use Visual Sourcesafe (and possibly other SCCs) to version control code and objects in place: see this MSDN article
This may help:
Sub AllCodeToDesktop()
'The reference for the FileSystemObject Object is Windows Script Host Object Model
'but it not necessary to add the reference for this procedure.
Dim fs As Object
Dim f As Object
Dim strMod As String
Dim mdl As Object
Dim i As Integer
Set fs = CreateObject("Scripting.FileSystemObject")
'Set up the file.
Set f = fs.CreateTextFile(SpFolder("Desktop") & "\" _
& Replace(CurrentProject.Name, ".", "") & ".txt")
'For each component in the project ...
For Each mdl In VBE.ActiveVBProject.VBComponents
'using the count of lines ...
i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
'put the code in a string ...
If VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.CountOfLines > 0 Then
strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.Lines(1, i)
End If
'and then write it to a file, first marking the start with
'some equal signs and the component name.
f.writeline String(15, "=") & vbCrLf & mdl.Name _
& vbCrLf & String(15, "=") & vbCrLf & strMod
Next
'Close eveything
f.Close
Set fs = Nothing
End Sub
Function SpFolder(SpName As String)
'Special folders
SpFolder = CreateObject("WScript.Shell").SpecialFolders(SpName)
End Function
From: http://wiki.lessthandot.com/index.php/Code_and_Code_Windows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With