投稿日 | : 2007/01/04(Thu) 15:55 |
投稿者 | : こう |
Eメール | : |
URL | : |
タイトル | : エラーが発見されたテキストボックスへのフォーカスの移動 |
フォームにテキストボックスが10個あります。各テキスト
ボックスに入力された文字のチェックを行い、入力できない
文字が存在した場合、テキストボックスの背景色の変更と該当
のテキストボックスへフォーカスを設定しています。
すべのテキストボックスをチェック後、複数のテキストボックス
がエラーの対象となった場合、最初に見つかった(エラーが発見
された)テキストボックスにフォーカスを移動させたいのですが、
どのようにすればよいのですか。
つまり、すべてのテキストボックスをチェックした後、最初に
見つかったテキストボックスにフォーカスを設定したいのですが
どうすればよいのですか。
背景色を変えるのは、入力できない文字が見つかった時点で
設定できます。また、この時、合わせてフォーカスを設定する
と、結局は、一番最後に見つかったテキストボックスになって
しまう。
/*--------------------------------------------------*/
Private Sub Command1_Click()
If ChkTextBox <> True Then
Exit Sub
End If
End Sub
Private Function ChkTextBox() As Boolean
Dim chk_flg As Boolean
ChkTextBox = True
chk_flg = True
If ChkKinsokuChr(Text1) = False Then chk_flg = False
If ChkKinsokuChr(Text2) = False Then chk_flg = False
If ChkKinsokuChr(Text3) = False Then chk_flg = False
If ChkKinsokuChr(Text4) = False Then chk_flg = False
If ChkKinsokuChr(Text5) = False Then chk_flg = False
If ChkKinsokuChr(Text6) = False Then chk_flg = False
If ChkKinsokuChr(Text7) = False Then chk_flg = False
If ChkKinsokuChr(Text8) = False Then chk_flg = False
If ChkKinsokuChr(Text9) = False Then chk_flg = False
If ChkKinsokuChr(Text10) = False Then chk_flg = False
If chk_flg = False Then
ChkTextBox = False
MsgBox "入力できない文字が存在します。再入力して下さい。"
Exit Function
End If
End Function
Private Function ChkKinsokuChr(ByVal MyTextBox As TextBox) As Boolean
Dim I As Integer
ChkKinsokuChr = True
チェック処理
背景色の変更処理
etc
End Function