ついでにクエリのsqlも検索できるように書き出す。
- vbaのモジュールに書いてイミディエイトウィンドウで実行
Public Sub CreateAllControlSource()
Dim objFile As Object
Dim strProjectPath As String
Dim strFilePath As String
Dim objWrite As Object
Dim accObj As AccessObject
Dim ctl As Control
Dim Dbs As DAO.Database
Dim Qdf As DAO.QueryDef
Set objFile = CreateObject("Scripting.FileSystemObject")
'ファイルの書き出し
strProjectPath = CurrentProject.Path
strFilePath = objFile.BuildPath(strProjectPath, "WriteData.txt")
Set objWrite = objFile.OpenTextFile(strFilePath, 2, True)
objWrite.WriteLine "----------------- フォーム ---------------------"
'フォームを書き込み
For Each accObj In CurrentProject.AllForms
objWrite.WriteLine accObj.Name
' Debug.Print accObj.Name
DoCmd.OpenForm accObj.Name, acDesign, , , , acHidden
'コントロールを書き込み
objWrite.WriteLine " レコードソース " & Forms(accObj.Name).RecordSource
For Each ctl In Forms(accObj.Name).Controls
If ctl.ControlType = acTextBox Then
'コントロールソースの書き込み
objWrite.WriteLine " " & ctl.Name & " " & ctl.ControlSource
End If
' Debug.Print ctl.Name
Next ctl
DoCmd.Close acForm, accObj.Name
Next accObj
objWrite.WriteLine "----------------- レポート---------------------"
For Each accObj In CurrentProject.AllReports
' Debug.Print accObj.Name
objWrite.WriteLine accObj.Name
' Debug.Print accObj.Name
DoCmd.OpenReport accObj.Name, acDesign, , , , acHidden
'コントロールの書き込み
objWrite.WriteLine " レコードソース " & Reports(accObj.Name).RecordSource
For Each ctl In Reports(accObj.Name).Controls
If ctl.ControlType = acTextBox Then
'コントロールソースの書き込み
objWrite.WriteLine " " & ctl.Name & " " & ctl.ControlSource
End If
' Debug.Print ctl.Name
Next ctl
DoCmd.Close acReport, accObj.Name
Next accObj
'データベースセット
Set Dbs = CurrentDb
'クエリ分ループ
For Each Qdf In Dbs.QueryDefs
objWrite.WriteLine Qdf.Name
objWrite.WriteLine " " & Qdf.sql
Next Qdf
Set Dbs = Nothing
objWrite.Close
Set objWrite = Nothing
Set objFile = Nothing
End Sub
0 件のコメント:
コメントを投稿