0
1

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のレポートでトレースに必要なファイルパスやレポート名を動的に印字

Last updated at Posted at 2022-08-30

概要

Accessのレポートに 『Access自身のファイルパス』『レポート名』 などを印字したい。
ただ印字するのではなく、Accessのファイル名やレポート名を変更してもメンテ不要にしたい。
(動的に値を印字)

何でこんなことをするのか?

トレースしやすくするため。

トレースとは どこに置いてあるAccessファイルどのレポート から出力した印刷物かを調べる作業のこと。

Accessファイルはコピペやファイルの移動が、 ユーザー側で簡単にできてしまいがち
また、『リファクタリングによるレポート名変更』や『コピペで別名レポート作成』も考えられる。
なので、動的に値を印字した方がいい。

やり方(VBA不使用)

テキストボックスのコントロールソースに記述するだけで実装できる。

Access自身のファイルパスを印字する時にコントロールソースに設定する値
=[Application].[CurrentProject].[FullName]

テキストボックスのコントロールソースに Me は使えないので、 Report を使う。

レポート名を印字する時にコントロールソースに設定する値
=[Report].[Name]
現在時刻を印字する時にコントロールソースに設定する値
=Now()

実装例

image.png

image.png

やり方(VBA使用)

VBA不使用の場合の応用なので詳細は割愛。

サンプルコード
Private Sub ページヘッダーセクション_Format(Cancel As Integer, FormatCount As Integer)
    
    Me.テキスト359.Value = Application.CurrentProject.FullName
    Me.テキスト358.Value = Report.Name
    Me.テキスト360.Value = Now()
    
End Sub

VBAの場合は実装が少し面倒だけど、 なぜこの値を印字しているのか というコメントを残せるメリットがある。

参考サイトさん

バージョン

Windows 10 Pro 21H2 OSビルド 19044.1889
Microsoft Access for Microsoft 365 MSO (バージョン 2207 ビルド 16.0.15427.20166) 32 ビット

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?