- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我参与更新 Access 解决方案。它有大量的 VBA、大量的查询、少量的表格以及一些用于数据输入和报告生成的表单。它是 Access 的理想候选者。
我想更改表设计、VBA、查询和表单。如何使用版本控制跟踪我的更改? (我们使用 Subversion,但这适用于任何风格)我可以将整个 mdb 保存在 subversion 中,但这将存储一个二进制文件,而且我无法知道我刚刚更改了一行 VBA 代码。
我考虑过将 VBA 代码复制到单独的文件中,然后保存它们,但我发现它们很快就与数据库中的内容不同步。
最佳答案
我们用 VBScript 编写了自己的脚本,该脚本使用 Access 中未记录的 Application.SaveAsText() 来导出所有代码、表单、宏和报告模块。就在这里,它应该给你一些指导。 (注意:有些消息是德语,但您可以轻松更改。)
编辑:总结以下各种评论:我们的项目采用 .adp 文件。为了在 .mdb/.accdb 中实现此功能,您必须将 OpenAccessProject() 更改为 OpenCurrentDatabase()。 (更新为在看到 .adp 扩展名时使用 OpenAccessProject()
,否则使用 OpenCurrentDatabase()
。)
分解.vbs:
' Usage:
' CScript decompose.vbs <input file> <path>
' Converts all modules, classes, forms and macros from an Access Project file (.adp) <input file> to
' text and saves the results in separate files to <path>. Requires Microsoft Access.
'
Option Explicit
const acForm = 2
const acModule = 5
const acMacro = 4
const acReport = 3
' BEGIN CODE
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
dim sADPFilename
If (WScript.Arguments.Count = 0) then
MsgBox "Bitte den Dateinamen angeben!", vbExclamation, "Error"
Wscript.Quit()
End if
sADPFilename = fso.GetAbsolutePathName(WScript.Arguments(0))
Dim sExportpath
If (WScript.Arguments.Count = 1) then
sExportpath = ""
else
sExportpath = WScript.Arguments(1)
End If
exportModulesTxt sADPFilename, sExportpath
If (Err <> 0) and (Err.Description <> NULL) Then
MsgBox Err.Description, vbExclamation, "Error"
Err.Clear
End If
Function exportModulesTxt(sADPFilename, sExportpath)
Dim myComponent
Dim sModuleType
Dim sTempname
Dim sOutstring
dim myType, myName, myPath, sStubADPFilename
myType = fso.GetExtensionName(sADPFilename)
myName = fso.GetBaseName(sADPFilename)
myPath = fso.GetParentFolderName(sADPFilename)
If (sExportpath = "") then
sExportpath = myPath & "\Source\"
End If
sStubADPFilename = sExportpath & myName & "_stub." & myType
WScript.Echo "copy stub to " & sStubADPFilename & "..."
On Error Resume Next
fso.CreateFolder(sExportpath)
On Error Goto 0
fso.CopyFile sADPFilename, sStubADPFilename
WScript.Echo "starting Access..."
Dim oApplication
Set oApplication = CreateObject("Access.Application")
WScript.Echo "opening " & sStubADPFilename & " ..."
If (Right(sStubADPFilename,4) = ".adp") Then
oApplication.OpenAccessProject sStubADPFilename
Else
oApplication.OpenCurrentDatabase sStubADPFilename
End If
oApplication.Visible = false
dim dctDelete
Set dctDelete = CreateObject("Scripting.Dictionary")
WScript.Echo "exporting..."
Dim myObj
For Each myObj In oApplication.CurrentProject.AllForms
WScript.Echo " " & myObj.fullname
oApplication.SaveAsText acForm, myObj.fullname, sExportpath & "\" & myObj.fullname & ".form"
oApplication.DoCmd.Close acForm, myObj.fullname
dctDelete.Add "FO" & myObj.fullname, acForm
Next
For Each myObj In oApplication.CurrentProject.AllModules
WScript.Echo " " & myObj.fullname
oApplication.SaveAsText acModule, myObj.fullname, sExportpath & "\" & myObj.fullname & ".bas"
dctDelete.Add "MO" & myObj.fullname, acModule
Next
For Each myObj In oApplication.CurrentProject.AllMacros
WScript.Echo " " & myObj.fullname
oApplication.SaveAsText acMacro, myObj.fullname, sExportpath & "\" & myObj.fullname & ".mac"
dctDelete.Add "MA" & myObj.fullname, acMacro
Next
For Each myObj In oApplication.CurrentProject.AllReports
WScript.Echo " " & myObj.fullname
oApplication.SaveAsText acReport, myObj.fullname, sExportpath & "\" & myObj.fullname & ".report"
dctDelete.Add "RE" & myObj.fullname, acReport
Next
WScript.Echo "deleting..."
dim sObjectname
For Each sObjectname In dctDelete
WScript.Echo " " & Mid(sObjectname, 3)
oApplication.DoCmd.DeleteObject dctDelete(sObjectname), Mid(sObjectname, 3)
Next
oApplication.CloseCurrentDatabase
oApplication.CompactRepair sStubADPFilename, sStubADPFilename & "_"
oApplication.Quit
fso.CopyFile sStubADPFilename & "_", sStubADPFilename
fso.DeleteFile sStubADPFilename & "_"
End Function
Public Function getErr()
Dim strError
strError = vbCrLf & "----------------------------------------------------------------------------------------------------------------------------------------" & vbCrLf & _
"From " & Err.source & ":" & vbCrLf & _
" Description: " & Err.Description & vbCrLf & _
" Code: " & Err.Number & vbCrLf
getErr = strError
End Function
如果您需要可点击的命令,请创建一个名为“decompose.cmd”的文件,而不是使用命令行
cscript decompose.vbs youraccessapplication.adp
默认情况下,所有导出的文件都会进入 Access 应用程序的“Scripts”子文件夹中。 .adp/mdb 文件也被复制到此位置(带有“stub”后缀)并删除所有导出的模块,使其非常小。
您必须将此 stub 与源文件一起 checkin ,因为大多数 Access 设置和自定义菜单栏无法以任何其他方式导出。如果您确实更改了某些设置或菜单,请务必仅提交对此文件的更改。
注意:如果您的应用程序中定义了任何 Autoexec-Makros,则在调用分解时可能必须按住 Shift 键,以防止它执行并干扰导出!
当然,还有反向脚本,从“源”目录构建应用程序:
compose.vbs:
' Usage:
' WScript compose.vbs <file> <path>
' Converts all modules, classes, forms and macros in a directory created by "decompose.vbs"
' and composes then into an Access Project file (.adp). This overwrites any existing Modules with the
' same names without warning!!!
' Requires Microsoft Access.
Option Explicit
const acForm = 2
const acModule = 5
const acMacro = 4
const acReport = 3
Const acCmdCompileAndSaveAllModules = &H7E
' BEGIN CODE
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
dim sADPFilename
If (WScript.Arguments.Count = 0) then
MsgBox "Please enter the file name!", vbExclamation, "Error"
Wscript.Quit()
End if
sADPFilename = fso.GetAbsolutePathName(WScript.Arguments(0))
Dim sPath
If (WScript.Arguments.Count = 1) then
sPath = ""
else
sPath = WScript.Arguments(1)
End If
importModulesTxt sADPFilename, sPath
If (Err <> 0) and (Err.Description <> NULL) Then
MsgBox Err.Description, vbExclamation, "Error"
Err.Clear
End If
Function importModulesTxt(sADPFilename, sImportpath)
Dim myComponent
Dim sModuleType
Dim sTempname
Dim sOutstring
' Build file and pathnames
dim myType, myName, myPath, sStubADPFilename
myType = fso.GetExtensionName(sADPFilename)
myName = fso.GetBaseName(sADPFilename)
myPath = fso.GetParentFolderName(sADPFilename)
' if no path was given as argument, use a relative directory
If (sImportpath = "") then
sImportpath = myPath & "\Source\"
End If
sStubADPFilename = sImportpath & myName & "_stub." & myType
' check for existing file and ask to overwrite with the stub
if (fso.FileExists(sADPFilename)) Then
WScript.StdOut.Write sADPFilename & " exists. Overwrite? (y/n) "
dim sInput
sInput = WScript.StdIn.Read(1)
if (sInput <> "y") Then
WScript.Quit
end if
fso.CopyFile sADPFilename, sADPFilename & ".bak"
end if
fso.CopyFile sStubADPFilename, sADPFilename
' launch MSAccess
WScript.Echo "starting Access..."
Dim oApplication
Set oApplication = CreateObject("Access.Application")
WScript.Echo "opening " & sADPFilename & " ..."
If (Right(sStubADPFilename,4) = ".adp") Then
oApplication.OpenAccessProject sADPFilename
Else
oApplication.OpenCurrentDatabase sADPFilename
End If
oApplication.Visible = false
Dim folder
Set folder = fso.GetFolder(sImportpath)
' load each file from the import path into the stub
Dim myFile, objectname, objecttype
for each myFile in folder.Files
objecttype = fso.GetExtensionName(myFile.Name)
objectname = fso.GetBaseName(myFile.Name)
WScript.Echo " " & objectname & " (" & objecttype & ")"
if (objecttype = "form") then
oApplication.LoadFromText acForm, objectname, myFile.Path
elseif (objecttype = "bas") then
oApplication.LoadFromText acModule, objectname, myFile.Path
elseif (objecttype = "mac") then
oApplication.LoadFromText acMacro, objectname, myFile.Path
elseif (objecttype = "report") then
oApplication.LoadFromText acReport, objectname, myFile.Path
end if
next
oApplication.RunCommand acCmdCompileAndSaveAllModules
oApplication.Quit
End Function
Public Function getErr()
Dim strError
strError = vbCrLf & "----------------------------------------------------------------------------------------------------------------------------------------" & vbCrLf & _
"From " & Err.source & ":" & vbCrLf & _
" Description: " & Err.Description & vbCrLf & _
" Code: " & Err.Number & vbCrLf
getErr = strError
End Function
同样,这与一个同伴“compose.cmd”一起包含:
cscript compose.vbs youraccessapplication.adp
它会要求您确认覆盖当前的应用程序,并首先创建备份(如果您这样做)。然后它收集源目录中的所有源文件并将它们重新插入到 stub 中。
玩得开心!
关于ms-access - 如何在 Access 开发中使用版本控制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/187506/
我正在尝试编写 Access Access 数据库的脚本,以便在命令行上使用。 Access 数据库使用工作组文件进行保护。 Dim oApp, sWGF,myWS Set sApp = Create
我有一个包含数据表的表格。我希望用户能够选择多行,单击按钮并运行一些 sql 查询并对这些行执行一些工作。 查看我的 VBA 代码,我发现如何使用 CurrentRecord 属性 Access 最后
如果我在某个网络位置有 Microsoft Access 2007 数据库,那么可以使用该数据库的客户端计算机的数量是否有限制?客户端不会安装 Access,而是使用 Access Runtime 2
我正在开发一个注册系统。但我收到此错误:You tried to execute a query that does not include the specified expression.. 我正
我有一个产品设计为使用 MS Access 文件作为数据库的桌面产品。 现在,一些用户需要将它安装在几台 PC(比如说 2 或 3 台)上并共享数据库。 我想将 MS Access 文件放在共享文件夹
我接手了一个旧的软件项目,该项目使用 MS Access 数据库来存储数据。但是数据库不会在 Access 中打开,如下所示: "You do not have the necessary permi
我有一个文件夹,里面装满了 100 多个 Access97 文件。我需要将它们全部更新到 Access2003。 我可以手动完成,但使用 VBA 可能会快很多。 有没有人会有一个片段可以做到这一点?或
我正在通过 SQL Server 迁移助手 (SSMA) 将数据从 Access 数据库迁移到 SQL Server。 Access 应用程序将继续与转换为链接表的本地表一起使用。 一个连续的表单在加
我正在通过 SQL Server 迁移助手 (SSMA) 将数据从 Access 数据库迁移到 SQL Server。 Access 应用程序将继续与转换为链接表的本地表一起使用。 一个连续的表单在加
我的公司用 Visual Basic 6 开发了一个应用程序。 该应用程序通过 ODBC 数据源使用 Access 数据库。 Access 数据库是一个扩展名为“.mdb”的文件。 在以下环境中运行应
我一直在尝试让 Microsoft Access 从主 Access 窗口中“退出”,以便我可以隐藏 Access 窗口并仅在桌面上显示表单,以便可以轻松地将其放置在其他应用程序旁边。 起初我发现了一
我想在 access 2010 中使用 access 2000 和 2003 数据库。由于我不想检查一切是否手动工作,我正在寻找一种工具来分析 VBA 代码以查找使用 access 2010 发生的错
所以我有一个 Excel 工作簿,其中有一个很好的 shaperange 对象的全局 map 。通过一些非常简单的代码,我可以更改颜色、将国家/地区集合分组和取消分组为数组等......并且效果非常好
我们希望有大约 35-40 人通过共享驱动器上的脚本写入 Access 数据库。这些指标分解为他们需要每小时写大约 3-7 次。 Access 会支持这一点而不会对我产生影响吗? 是的,我很乐意将其用
我正在寻找一种使用 VBA 代码从外部数据库文件中删除 VBA 模块的方法。名为“myfile.accdb”的外部文件有一个名为“mod1”的模块,我希望能够在单独的项目中使用 VBA 代码删除该模块
我在 Access 2003 数据库(在 Access 2007 中开发)中有三个表单,它们处于父级 -> 子级 -> 孙子级关系中。在子窗体的 'Form_Load' 子窗体中,我设置了孙子窗体的一
MS Access 2007 存在拒绝在设计模式下显示表单的问题。我可以看到表单的代码(如果我查看显示表单的按钮的事件属性),但我看不到作为 GUI 布局的表单。而且,当我尝试从应用程序的主窗口调用此
我编写了代码,使用 Excel 中的下拉列表提供的标准将两个表连接起来,然后将数据返回到电子表格上的特定位置(工作表上已经有标题)。 这在我的机器上和其他机器上使用 MS Access 的机器上都可以
我正在开始构建一个应用程序,该应用程序从给定的根路径开始遍历文件夹结构,并将所有找到的 Access 1997 .mdb 文件转换为较新的 Access 2007/2010 .accdb 格式。但是,
我有一个表单和一个按钮。我想通过单击按钮打开另一个表单,并将参数从父表单传递到子表单(子表单的 RecordSource 有参数)。我该怎么做? 最佳答案 您可以通过引用表单的对象来引用调用表单的任何
我是一名优秀的程序员,十分优秀!