Hallo Forum,
ich möchte in ein TextBox in UserForm das Datum vereinfacht eingeben. Dafür habe ich in Recherche ein Makro gefunden. Es funktioniert ganz gut, soweit man das Datum richtig eingibt, etwa so: 280202, bekomme ich 28.02.02. Wenn ich aber eine Eingabe in der Form: 990202 eingebe, erhalte ich 99.02.02. Das ist aber nicht richtig, oder? Es müsste eine Fehlermeldung erscheinen.
Makro trägt Textindex: 030598
Private Sub CommandButton1_Click()
frmDatum.Show
End Sub
'ClassModule: frmDatum
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub TextBox1_Change()
Dim Txt$
Txt = TextBox1.Text
If Txt = "" Then Exit Sub
If IsNumeric(Txt) = False Then GoTo ErrorHandler
If Len(Txt) = 6 Then
Txt = Left(Txt, 2) & "." & Mid(Txt, 3, 2) _
& "." & Right(Txt, 2)
If Not IsDate(Txt) Then
GoTo ErrorHandler
Else
TextBox1.Text = Txt
Exit Sub
End If
End If
Exit Sub
ErrorHandler:
Beep
MsgBox "Kein Datum!"
TextBox1.Text = ""
End Sub
Wie kann ich Makro umbauen das es Richtig funktioniert?
Bin VBA Anfänger. Bin für jede Hilfe sehr dankbar.
Bis bald
Jusuf