• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

最近、僕が作ってる某学会のシステムのコードをそのままコピペ。

ここでは都合上「アプリケーションの実行パス」となっていますが、気にしないでください。

   1  ' プロシージャ: Function
   2  ' 名前        : GetAppExecPath
   3  ' 機能        : アプリケーションの実行パスを取得する
   4  ' 引数        : なし
   5  ' 戻り値      : String
   6  ' 備考        : なし
   7  Public Function GetAppExecPath() As String
   8      
   9      GetAppExecPath = CurrentProject.Path & "\"
  10  
  11  End Function

たとえば、開いているデータベースファイルが "C:\Documents and Settings\y_tsuda\My Documents\test.mdb" だとすると、"C:\Documents and Settings\y_tsuda\My Documents\" を返してくれます。

開いているデータベースがどこのディレクトリにあるのかを取得するには、

   1  'C:\Documents and Settings\y_tsuda\My Documents
   2  CurrentProject.Path 

を使います。

ただ、このままだと最後に \ がついていないので、

   1  'C:\Documents and Settings\y_tsuda\My Documents\ <- \が入る
   2  CurrentProject.Path & "\" 

としておくのがいろいろと都合がいいと思います。

この CurrentProject オブジェクトには現在開いているデータベースについての情報が入ってそう(名前からして・・・)なので、いろいろと見てみると面白いかもしれません。

posted by Png y_tsuda on Tue 13 Jan 2009 at 18:53
Contents
[Access VBA] 開いているデータベースファイルのパスを取得する
Comments
Aleksey: The uname check is only due to a somewhat slopp... '11-2
Yu Tsuda: あぁ、そうですね、、syncすると戻ってしまいますね・・・。 ご指摘ありがとうございます!! '09-7
ursm: /usr/portage 以下のファイルは更新のたび元に戻ってしまうので、/etc/porta... '09-7
Yu Tsuda: 見た目だけでも、わざわざGentooをこういうリストに入れてるのがすごいなぁと思ったりしたので... '09-3
Leonard Chin (レオ): ただし、VirtualBoxで「Gentoo」などを選択しても、別にどのOSを入れても大丈夫だ... '09-3
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ