回答編集履歴
1
コード追記
answer
CHANGED
@@ -10,4 +10,23 @@
|
|
10
10
|
Exit Sub
|
11
11
|
End If
|
12
12
|
Me.textboxA.Value = CDate(s)
|
13
|
+
```
|
14
|
+
---
|
15
|
+
|
16
|
+
AfterUpdateでは SetFocus でフォーカスを戻せません。このイベントの後で次のフォーカスへ移動しますので。BeforeUpdate(またはExit)でイベント自体をキャンセルすること(Cancel = True)で、フォーカスが移動しなくなります。
|
17
|
+
|
18
|
+
```VBA
|
19
|
+
Private Sub textboxA_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
|
20
|
+
Dim s As String
|
21
|
+
s = Me.textboxA.Value
|
22
|
+
If s Like "########" Then s = Format(s, "@@@@/@@/@@")
|
23
|
+
If Not IsDate(s) Then
|
24
|
+
MsgBox "日付を入力してください。"
|
25
|
+
Cancel = True
|
26
|
+
Exit Sub
|
27
|
+
End If
|
28
|
+
textboxA = CDate(s)
|
29
|
+
End Sub
|
30
|
+
|
31
|
+
|
13
32
|
```
|