版本控制访问2007数据库和应用程序

时间:2021-09-15 15:37:48

I need to version control a Microsoft Access 2007 database and application. Currently everything is contained in a single mdb file.

我需要版本控制一个Microsoft Access 2007数据库和应用程序。目前,所有内容都包含在一个mdb文件中。

The application includes:

应用程序包括:

  • Forms
  • 形式
  • VBA code
  • VBA代码
  • Actual database
  • 实际的数据库

I would assume I need to separate the database from the forms/code. I would like to be able to version control the forms/code as text to support version diffs.

我假设我需要将数据库与表单/代码分开。我希望能够版本控制的形式/代码作为文本支持版本扩散。

At the moment I don't have access to SourceSafe (I heard there may be some access support) so I would prefer a solution that would work with subversion or git.

目前我没有对SourceSafe的访问权限(我听说可能有一些访问支持),所以我更喜欢使用subversion或git的解决方案。

3 个解决方案

#1


3  

Access 2007 has a feature where you can split a DB into its Tables/Queries (backend) and Forms/Reports (front-end). Since your question mentions only version controlling the forms and modules, this might be a more elegant solution. I don't know where modules go after the split, so that might be a stumbling block.

Access 2007有一个特性,您可以将DB拆分为它的表/查询(后端)和表单/报告(前端)。由于您的问题只涉及控制表单和模块的版本,这可能是一个更优雅的解决方案。我不知道拆分后模块将何去何从,所以这可能是一个绊脚石。

Microsoft offers VSTO (Visual Studio Tools for Office), which will let you develop in VS and run version control via any VS plugin (CVS/SVN/VSS/etc.).

微软提供了VSTO (Office的Visual Studio工具),它可以让你在VS中开发,并通过任何VS插件(CVS/SVN/VSS等)运行版本控制。

Finally, you can just directly connect to Visual Source Safe. This MSKB article has some good information and background to go through, while this Office Online article is designed for getting you up and running.

最后,您可以直接连接到Visual Source Safe。这篇MSKB文章提供了一些很好的信息和背景,而这篇Office在线文章则是为让您能够正常运行而设计的。

Ultimately, I would suggest against taking the code out of Access if at all possible. Assuming the VBA editor is your primary development environment, you'll be adding extra steps to your development process that cannot easily be automated. Every change you make will need to be manually exported, diff'd, and stored, and there is no Application.OnCompile event that you could use to export the changes. Even tougher, you'll have to manually import all changed source files from other developers when they do checkins.

最后,如果可能的话,我建议不要将代码从访问中删除。假设VBA编辑器是您的主要开发环境,那么您将为您的开发过程添加不容易自动化的额外步骤。您所做的每一个更改都需要手动导出、diff和存储,并且没有应用程序。可以用来导出更改的OnCompile事件。更困难的是,当其他开发人员进行签入时,您必须手动从他们那里导入所有修改过的源文件。

#2


2  

I use the code below to extract the vba code from Excel files, you may be able to modify this to extract from Access.

我使用下面的代码从Excel文件中提取vba代码,您可以修改它从Access中提取。

Sub ExtractVBACode(strSource, objFSO, strExportPath, objLogFile)
Dim objExcel
Dim objWorkbook
Dim objVBComponent
Dim strFileSuffix
Dim strExportFolder


Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = true

Set objWorkbook = objExcel.Workbooks.Open(Trim(strSource))

strExportFolder = strExportPath & objFSO.GetBaseName(objWorkbook.Name)

If Not objFSO.FolderExists(strExportFolder) Then
    objFSO.CreateFolder(strExportFolder)
End If

For Each objVBComponent In objWorkbook.VBProject.VBComponents
    Select Case objVBComponent.Type
        Case vbext_ct_ClassModule, vbext_ct_Document
            strFileSuffix = ".cls"
        Case vbext_ct_MSForm
            strFileSuffix = ".frm"
        Case vbext_ct_StdModule
            strFileSuffix = ".bas"
        Case Else
            strFileSuffix = ""
    End Select
    If strFileSuffix <> "" Then
        On Error Resume Next
        Err.Clear
        objVBComponent.Export strExportFolder & "\" & objVBComponent.Name & strFileSuffix
        If Err.Number <> 0 Then
            objLogFile.WriteLine ("Failed to export " & strExportFolder & "\" & objVBComponent.Name & strFileSuffix)
        Else
            objLogFile.WriteLine ("Export Successful: " & strExportFolder & "\" & objVBComponent.Name & strFileSuffix)
        End If
        On Error Goto 0
    End If
Next

objExcel.DisplayAlerts = False
objExcel.Quit

End Sub

终止子

Can you extract the forms as XML perhaps?

您可以将表单提取为XML吗?

#3


2  

I've struggled with this same problem. I originally wrote code very much like the existing answer. The trick is to get all of your modules onto the file system, but that method has some drawbacks. Going that route, you can get your forms and reports out of the VBA Projects, but you can't get them back in. So, I created a library as part of our Rubberduck VBE Add-in. The library I wrote takes care of importing and exporting all of your code to/from the VBA project to/from the repository as you seemlessly push, pull, and commit. It's a free and open source project, so feel free to download and install the latest version.

我也遇到过同样的问题。我最初编写的代码非常像现有的答案。诀窍是将所有模块都放到文件系统中,但是该方法有一些缺点。沿着这条路线,您可以从VBA项目中获得表单和报告,但是您不能将它们返回。因此,我创建了一个库作为Rubberduck VBE外接程序的一部分。我编写的库负责将您的所有代码导入和导出到/从VBA项目到/从存储库,因为您似乎不自觉地推、拉和提交。这是一个免费的开源项目,所以请下载并安装最新版本。

Here is an example of how the library is used. I'll be adding actual integration with the VBA editor in a future release.

这里有一个如何使用库的例子。我将在以后的版本中添加与VBA编辑器的实际集成。

Dim factory As New Rubberduck.SourceControlClassFactory 
Dim repo As Rubberduck.IRepository 
Dim git As ISourceControlProvider

Dim xl As New Excel.Application
xl.Visible = true
Dim wb As Excel.Workbook

Set wb = xl.Workbooks.Open("C:\Path\to\workbook.xlsm")

' create class instances to work with
Set repo = factory.CreateRepository(wb.VBProject.Name, "C:\Path\to\local\repository\SourceControlTest", "https://github.com/ckuhn203/SourceControlTest.git")
Set git = factory.CreateGitProvider(wb.VBProject, repo, "userName", "passWord")

' Create new branch to modify.
git.CreateBranch "NewBranchName"

' It is automatically checked out.
Debug.Print "Current Branch: " & git.CurrentBranch

' add a new standard (.bas) code module and a comment to that file
wb.VBProject.VBComponents.Add(vbext_ct_StdModule).CodeModule.AddFromString "' Hello There"

' add any new files to tracking
Dim fileStat As Rubberduck.FileStatusEntry
For Each fileStat In git.Status
    ' fileStat.FileStatus is a bitwise enumeration, so we use bitwise AND to test for equality here
    If fileStat.FileStatus And Rubberduck.FileStatus.Added Then
        git.AddFile fileStat.FilePath
    End If
Next

git.Commit "commit all modified files" 

' Revert the last commit, throwing away the changes we just made.
git.Revert

#1


3  

Access 2007 has a feature where you can split a DB into its Tables/Queries (backend) and Forms/Reports (front-end). Since your question mentions only version controlling the forms and modules, this might be a more elegant solution. I don't know where modules go after the split, so that might be a stumbling block.

Access 2007有一个特性,您可以将DB拆分为它的表/查询(后端)和表单/报告(前端)。由于您的问题只涉及控制表单和模块的版本,这可能是一个更优雅的解决方案。我不知道拆分后模块将何去何从,所以这可能是一个绊脚石。

Microsoft offers VSTO (Visual Studio Tools for Office), which will let you develop in VS and run version control via any VS plugin (CVS/SVN/VSS/etc.).

微软提供了VSTO (Office的Visual Studio工具),它可以让你在VS中开发,并通过任何VS插件(CVS/SVN/VSS等)运行版本控制。

Finally, you can just directly connect to Visual Source Safe. This MSKB article has some good information and background to go through, while this Office Online article is designed for getting you up and running.

最后,您可以直接连接到Visual Source Safe。这篇MSKB文章提供了一些很好的信息和背景,而这篇Office在线文章则是为让您能够正常运行而设计的。

Ultimately, I would suggest against taking the code out of Access if at all possible. Assuming the VBA editor is your primary development environment, you'll be adding extra steps to your development process that cannot easily be automated. Every change you make will need to be manually exported, diff'd, and stored, and there is no Application.OnCompile event that you could use to export the changes. Even tougher, you'll have to manually import all changed source files from other developers when they do checkins.

最后,如果可能的话,我建议不要将代码从访问中删除。假设VBA编辑器是您的主要开发环境,那么您将为您的开发过程添加不容易自动化的额外步骤。您所做的每一个更改都需要手动导出、diff和存储,并且没有应用程序。可以用来导出更改的OnCompile事件。更困难的是,当其他开发人员进行签入时,您必须手动从他们那里导入所有修改过的源文件。

#2


2  

I use the code below to extract the vba code from Excel files, you may be able to modify this to extract from Access.

我使用下面的代码从Excel文件中提取vba代码,您可以修改它从Access中提取。

Sub ExtractVBACode(strSource, objFSO, strExportPath, objLogFile)
Dim objExcel
Dim objWorkbook
Dim objVBComponent
Dim strFileSuffix
Dim strExportFolder


Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = true

Set objWorkbook = objExcel.Workbooks.Open(Trim(strSource))

strExportFolder = strExportPath & objFSO.GetBaseName(objWorkbook.Name)

If Not objFSO.FolderExists(strExportFolder) Then
    objFSO.CreateFolder(strExportFolder)
End If

For Each objVBComponent In objWorkbook.VBProject.VBComponents
    Select Case objVBComponent.Type
        Case vbext_ct_ClassModule, vbext_ct_Document
            strFileSuffix = ".cls"
        Case vbext_ct_MSForm
            strFileSuffix = ".frm"
        Case vbext_ct_StdModule
            strFileSuffix = ".bas"
        Case Else
            strFileSuffix = ""
    End Select
    If strFileSuffix <> "" Then
        On Error Resume Next
        Err.Clear
        objVBComponent.Export strExportFolder & "\" & objVBComponent.Name & strFileSuffix
        If Err.Number <> 0 Then
            objLogFile.WriteLine ("Failed to export " & strExportFolder & "\" & objVBComponent.Name & strFileSuffix)
        Else
            objLogFile.WriteLine ("Export Successful: " & strExportFolder & "\" & objVBComponent.Name & strFileSuffix)
        End If
        On Error Goto 0
    End If
Next

objExcel.DisplayAlerts = False
objExcel.Quit

End Sub

终止子

Can you extract the forms as XML perhaps?

您可以将表单提取为XML吗?

#3


2  

I've struggled with this same problem. I originally wrote code very much like the existing answer. The trick is to get all of your modules onto the file system, but that method has some drawbacks. Going that route, you can get your forms and reports out of the VBA Projects, but you can't get them back in. So, I created a library as part of our Rubberduck VBE Add-in. The library I wrote takes care of importing and exporting all of your code to/from the VBA project to/from the repository as you seemlessly push, pull, and commit. It's a free and open source project, so feel free to download and install the latest version.

我也遇到过同样的问题。我最初编写的代码非常像现有的答案。诀窍是将所有模块都放到文件系统中,但是该方法有一些缺点。沿着这条路线,您可以从VBA项目中获得表单和报告,但是您不能将它们返回。因此,我创建了一个库作为Rubberduck VBE外接程序的一部分。我编写的库负责将您的所有代码导入和导出到/从VBA项目到/从存储库,因为您似乎不自觉地推、拉和提交。这是一个免费的开源项目,所以请下载并安装最新版本。

Here is an example of how the library is used. I'll be adding actual integration with the VBA editor in a future release.

这里有一个如何使用库的例子。我将在以后的版本中添加与VBA编辑器的实际集成。

Dim factory As New Rubberduck.SourceControlClassFactory 
Dim repo As Rubberduck.IRepository 
Dim git As ISourceControlProvider

Dim xl As New Excel.Application
xl.Visible = true
Dim wb As Excel.Workbook

Set wb = xl.Workbooks.Open("C:\Path\to\workbook.xlsm")

' create class instances to work with
Set repo = factory.CreateRepository(wb.VBProject.Name, "C:\Path\to\local\repository\SourceControlTest", "https://github.com/ckuhn203/SourceControlTest.git")
Set git = factory.CreateGitProvider(wb.VBProject, repo, "userName", "passWord")

' Create new branch to modify.
git.CreateBranch "NewBranchName"

' It is automatically checked out.
Debug.Print "Current Branch: " & git.CurrentBranch

' add a new standard (.bas) code module and a comment to that file
wb.VBProject.VBComponents.Add(vbext_ct_StdModule).CodeModule.AddFromString "' Hello There"

' add any new files to tracking
Dim fileStat As Rubberduck.FileStatusEntry
For Each fileStat In git.Status
    ' fileStat.FileStatus is a bitwise enumeration, so we use bitwise AND to test for equality here
    If fileStat.FileStatus And Rubberduck.FileStatus.Added Then
        git.AddFile fileStat.FilePath
    End If
Next

git.Commit "commit all modified files" 

' Revert the last commit, throwing away the changes we just made.
git.Revert