Gruppe
DatumZeit
Problem
Wie kann ich in XL8 die Datumseingabe in ein Textfeld einer UserForm erzwingen?
StandardModule: basMain
Sub CallForm()
frmDatum.Show
End Sub
ClassModule: frmDatum
Private Sub cmdContinue_Click()
Unload Me
End Sub
Private Sub txtDate_Change()
Dim sTxt As String
If txtDate.Text = "" Then Exit Sub
sTxt = txtDate.Text
If Right(sTxt, 1) Like "[!0-9]" Then
txtDate.Text = Left(sTxt, Len(sTxt) - 1)
Exit Sub
End If
If IsNumeric(sTxt) = False Then GoTo ERRORHANDLER
If Len(sTxt) = 6 Then
sTxt = Left(sTxt, 2) & "." & Mid(sTxt, 3, 2) _
& "." & Right(sTxt, 2)
If Not IsDate(sTxt) Then
GoTo ERRORHANDLER
Else
txtDate.Text = sTxt
Exit Sub
End If
End If
Exit Sub
ERRORHANDLER:
Beep
MsgBox "Kein Datum!"
txtDate.Text = ""
txtDate.SetFocus
End Sub