1
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のタブコントロールで特殊なSetFocusをすると実行時エラー2110になる件

Last updated at Posted at 2022-10-17

概要

コンパイルエラーは無い。
SetFocusするオブジェクトは存在している。
なのに下記文言で例外。

実行時エラー'2110'
コントロール ※※ にフォーカスを移動することはできません。

発生する条件

下記のように別々のタブページに2つのオブジェクトがある。
image.png
image.png

そして『アクティブ時』『開く時』の両方で同じSetFocusをしている。

'フォームアクティブ時に実行される
Private Sub Form_Activate()
    Call focus
End Sub

'フォーム開く時に実行される
Private Sub Form_Open(Cancel As Integer)
    Call focus
End Sub

'『アクティブ時』『開く時』の両方で使う共通関数
Private Function focus()
    Me.txt_1.SetFocus
    Me.txt_2.SetFocus
End Function

↓実行時エラーで止まる。
image.png

蛇足

まず前提として同じ処理を無駄に何回も実行しない。

基本は『アクティブ時』に実行。
フォーム開く時だけ実行して欲しい なら『開く時』、という使い分けをしっかりした方がいいと思う。

『アクティブ時』 = フォーム開く時とサブ画面から戻ってきた時の両方で実行される。
『開く時』 = フォーム開く時に実行されるが、サブ画面から戻ってきた時には実行されない。

バージョン

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

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