LoginSignup
0
0

More than 3 years have passed since last update.

Accessが置かれているフォルダパスやフォーム一覧を取得できるCurrentProjectについて

Last updated at Posted at 2020-11-28

CurrentProjectってなんぞ?

例えば Accessファイルが置かれているフォルダーのパス を取得できたりします。(下記コード)

CurrentProject.Path

公式ドキュメント

よく使うやつ概要

名前 概要
CurrentProject.AllForms フォーム一覧取得できます。『開いているフォームをすべて閉じる』なんて機能を作る際、動的にフォーム一覧を取得できるので便利です。
CurrentProject.AllReports レポート一覧取得できます。利便性はAllFormsとほぼ同じ。
CurrentProject.Path Accessファイルが置かれているフォルダーパスを取得できます。一番使います。末尾に『\』が付かないので注意。これを使うことでAccessファイルを移動したり、親フォルダーをリネームしても大丈夫なシステムにできます。

とにかくCurrentProjectが抱えてるやつを全部確認してみるぞ関数

CurrentProjectで取得できるものをDebug.Printにとにかく出力してみる関数です。

Private Function doit()


    Const break_ As String = vbCrLf & "-----------------------------------------" & vbCrLf
    Dim i_ As Long
    Dim tmp_ As Variant


    Debug.Print "AccessConnectionだよ"
    Debug.Print CurrentProject.AccessConnection
    Debug.Print break_


    Debug.Print "AllFormsだよ"
    Debug.Print "(ひとまず各フォームの名前)"
    For i_ = 0 To CurrentProject.AllForms.Count - 1
        Debug.Print CurrentProject.AllForms(i_).Name
    Next
    Debug.Print break_


    Debug.Print "AllMacrosだよ"
    Debug.Print "(ひとまず各マクロの値)"
    For i_ = 0 To CurrentProject.AllMacros.Count - 1
        Debug.Print CurrentProject.AllMacros(i_).Name
    Next
    Debug.Print break_


    Debug.Print "AllModulesだよ"
    Debug.Print "(ひとまず各クラスや標準モジュールの値)"
    For i_ = 0 To CurrentProject.AllModules.Count - 1
        Debug.Print CurrentProject.AllModules(i_).Name
    Next
    Debug.Print break_


    Debug.Print "AllReportsだよ"
    Debug.Print "(ひとまず各レポートの名前)"
    For i_ = 0 To CurrentProject.AllReports.Count - 1
        Debug.Print CurrentProject.AllReports(i_).Name
    Next
    Debug.Print break_


    Debug.Print "Applicationだよ"
    Debug.Print "(ひとまずApplication.Nameの値)"
    Debug.Print CurrentProject.Application.Name
    Debug.Print break_


    Debug.Print "BaseConnectionStringだよ"
    Debug.Print CurrentProject.BaseConnectionString
    Debug.Print break_


    Debug.Print "Connectionだよ"
    Debug.Print CurrentProject.Connection
    Debug.Print break_


    Debug.Print "FileFormatだよ"
    Debug.Print CurrentProject.FileFormat
    Debug.Print break_


    Debug.Print "FullNameだよ"
    Debug.Print CurrentProject.FullName
    Debug.Print break_


    Debug.Print "ImportExportSpecificationsだよ"
    Debug.Print "(ひとまずインポートやエクスポート操作の名前)"
    For i_ = 0 To CurrentProject.AllForms.Count - 1
        Debug.Print CurrentProject.ImportExportSpecifications(i_).Name
    Next
    Debug.Print break_


    Debug.Print "IsConnectedだよ"
    Debug.Print CurrentProject.IsConnected
    Debug.Print break_


    Debug.Print "IsSQLBackendだよ"
    Debug.Print CurrentProject.IsSQLBackend
    Debug.Print break_


    Debug.Print "IsTrustedだよ"
    Debug.Print CurrentProject.IsTrusted
    Debug.Print break_


    Debug.Print "IsWebだよ"
    Debug.Print CurrentProject.IsWeb
    Debug.Print break_


    Debug.Print "Nameだよ"
    Debug.Print CurrentProject.Name
    Debug.Print break_


    Debug.Print "Parentだよ"
    Debug.Print "※用途不明です(´・ω・`)"
    'https://docs.microsoft.com/ja-jp/office/vba/api/access.currentproject.parent
    'Debug.Print CurrentProject.Parent
    Debug.Print break_


    Debug.Print "Pathだよ"
    Debug.Print CurrentProject.Path
    Debug.Print break_


    Debug.Print "ProjectTypeだよ"
    Debug.Print CurrentProject.ProjectType
    Debug.Print break_


    Debug.Print "Propertiesだよ"
    Debug.Print "(ひとまずApplication.Versionの値)"
    Set tmp_ = CurrentProject.Properties
    Debug.Print tmp_.Application.Version
    Debug.Print break_


    Debug.Print "RemovePersonalInformationだよ"
    Debug.Print CurrentProject.RemovePersonalInformation
    Debug.Print break_


    Debug.Print "Resourcesだよ"
    Debug.Print "(ひとまず各リソースの名前)"
    For i_ = 0 To CurrentProject.Resources.Count - 1
        Debug.Print CurrentProject.Resources(i_).Name
    Next
    Debug.Print break_


    Debug.Print "WebSiteだよ"
    Debug.Print CurrentProject.WebSite
    Debug.Print break_


End Function

蛇足

「まったく使わないだろうな…」と思う情報から、今まで使ったなかったけど、意外に役立ちそうな情報もあります。

  • IsConnected
  • IsSQLBackend
  • IsTrusted

この辺は排他制御なんかで使えそうな気がします。

バージョン

Windows10 Pro バージョン1909 OSビルド19042.630
Access for Microsoft 365 MSO(16.0.13328.20334)32ビット

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0