Accessのフォーム、レポートなどの定義をエクポート、インポート  次の文書


Accessのフォーム、レポートなどの定義とイベントプロシージャを外部ファイルに書き出す。
便利なエディタで修正後、元のAccess又は別のAccessでインポート。


Option Compare Database
Option Explicit

'Export
Public Sub ExportModules()
Dim outputDir As String
Dim currentDat As Object
Dim currentProj As Object

outputDir = GetDir(CurrentDb.Name)
Set currentDat = Application.CurrentData
Set currentProj = Application.CurrentProject
ExportObjectType acQuery, currentDat.AllQueries, outputDir, ".qry"
ExportObjectType acForm, currentProj.AllForms, outputDir, ".frm"
ExportObjectType acReport, currentProj.AllReports, outputDir, ".rpt"
ExportObjectType acMacro, currentProj.AllMacros, outputDir, ".mcr"
ExportObjectType acModule, currentProj.AllModules, outputDir, ".bas"
End Sub

'ファイル名のディレクトリ部分を返す
Private Function GetDir(FileName As String) As String
Dim p As Integer

GetDir = FileName
p = InStrRev(FileName, "\")
If p > 0 Then GetDir = Left(FileName, p - 1)
End Function

'特定の種類のオブジェクトをエクスポートする
Private Sub ExportObjectType(ObjType As Integer, _
ObjCollection As Variant, Path As String, Ext As String)

Dim obj As Variant
Dim filePath As String

For Each obj In ObjCollection
filePath = Path & "\dbObj\" & obj.Name & Ext
SaveAsText ObjType, obj.Name, filePath
Debug.Print "Save " & obj.Name
Next
End Sub

'import objects
Public Sub ImportModules()
Dim inputDir As String
Dim currentDat As Object
Dim currentProj As Object

inputDir = GetDir(CurrentDb.Name) & "\dbObj\"
Set currentDat = Application.CurrentData
Set currentProj = Application.CurrentProject
ImportObjectType (inputDir)
End Sub

'import all objects in a folder
Private Sub ImportObjectType(Path As String)

Dim currentDat As Object
Dim currentProj As Object

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim folder As Object
Dim myFile, objectname, objecttype
Set folder = CreateObject _
("Scripting.FileSystemObject").GetFolder(Path)
Dim oApplication

For Each myFile In folder.Files
objecttype = fso.GetExtensionName(myFile.Name)
objectname = fso.GetBaseName(myFile.Name)

If (objecttype = "frm") Then
Application.LoadFromText acForm, objectname, myFile.Path
ElseIf (objecttype = "bas") Then
Application.LoadFromText acModule, objectname, myFile.Path
ElseIf (objecttype = "mcr") Then
Application.LoadFromText acMacro, objectname, myFile.Path
ElseIf (objecttype = "rpt") Then
Application.LoadFromText acReport, objectname, myFile.Path
ElseIf (objecttype = "qry") Then
Application.LoadFromText acQuery, objectname, myFile.Path
End If
Next
End Sub

実行させると
実行時エラー'2128'
メニューのインポート中にエラーが発生しました。
となり
終了(E) デバッグ(D) で終了を選択

errors.txt 下記のような報告がでる
----------------------------------------------------
オブジェクト 'メニュー' のインポート中にエラーが発生しました。
行163でエラーが発生しました。
このコントロールには、このプロパティは適用されません。
----------------------------------------------------

今回は "メニュー.frm" の163行目
NoSaveCTIWhenDisabled =1
を削除して再度実行しインポート成功しました。

参照サイト
https://nameuntitled.hatenablog.com/entry/2016/08/26/185144

NoSaveCTIWhenDisabled =1 の対策サイトは
https://social.msdn.microsoft.com/Forums/office/en-US/691887f4-b345-4ea0-9158-6183e812bfa2/cant-create-database-from-sourcesafe-in-access2010-nosavectiwhendisabled?forum=accessdev

ですがまだ試していません

 




← 左の文字をここへ入力後 登録ボタンをクリックしてください

(サイト管理者承認後掲載されます)