掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
LOST_FOCUSを発動させたくない (ID:123259)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
クラスとWithEventsを使って共通関数みたいにしてみるとかは? 以下例(動作保証無し) Private objTxtCls() As ClsTxt Private Sub Form_Load() Dim lngFor As Long Dim lngCount As Long lngCount = 0 For lngFor = 0 To Me.Controls.Count - 1 If Left(Me.Controls(lngFor).Name, 4) = "Text" Then lngCount = lngCount + 1 ReDim Preserve objTxtCls(1 To lngCount) Set objTxtCls(lngCount) = New ClsTxt Call objTxtCls(lngCount).GetBtnObj(Me.Controls(lngFor)) End If Next End Sub Private Function chkTxt(objTxt As TextBox) As Boolean Dim lngFor As Long chkTxt = True For lngFor = 1 To UBound(objTxtCls) If objTxtCls(lngFor).objTxt = objTxt Then If objTxtCls(lngFor).lngID = 0 Then chkTxt = False End If End If Next End Function Private Sub Text1_LostFocus() If Not chkTxt(Text1) Then Exit Sub End If If Text1.Text = "test" Then Text1.SetFocus End If End Sub Private Sub Text2_LostFocus() If Not chkTxt(Text2) Then Exit Sub End If '= 処理 End Sub --- ClsTxt.cls ----------------------------------- Public WithEvents objTxt As TextBox Public lngID As Long Public Sub GetBtnObj(objBuf As TextBox) Set objTxt = objBuf lngID = 0 End Sub Private Sub objTxt_GotFocus() If objTxt.Parent.ActiveControl = objTxt Then lngID = 1 End If End Sub Private Sub objTxt_LostFocus() lngID = 0 End Sub
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.