0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AccessのVBAで自身の名前(フォーム名やクラス名など)を取得

Posted at

やり方

フォームとレポートでは可。クラスでは例外になってしまいます。
Me.Name
フォーム、レポート、クラスの3種全てで可。
TypeName(Me)

動作確認(フォーム)

image.png

Debug.Print "Me.Nameの結果は" & Me.Name
Debug.Print "TypeName(Me)の結果は" & TypeName(Me)

image.png

動作確認(レポート)

image.png

Debug.Print "Me.Nameの結果は" & Me.Name
Debug.Print "TypeName(Me)の結果は" & TypeName(Me)

image.png

動作確認(クラス)

image.png

Debug.Print "TypeName(Me)の結果は" & TypeName(Me)

image.png

標準モジュール

探したのですが、標準モジュール自身の名前を動的に取得する方法は見つかりませんでした…。

蛇足

ログ出力に使うなら TypeName(Me) がおススメ。
フォーム、レポート、クラスの全ておいて 同じ書き方で統一できる ため。

  • 表記揺れが発生しない。
  • 覚えることが少ない。

参考サイトさん

バージョン

Microsoft Windows [Version 10.0.19045.3803]
Microsoft Access for Microsoft 365 MSO (バージョン 2311 ビルド 16.0.17029.20108) 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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?