Supportnet / Forum / Tabellenkalkulation
VBA Userform Datumsüberprüfung mit bestimmter Formatierung
Frage
Hallo zusammen,
Ich versuche vergeblich in einer Textbox in einem Formular ( Userform) eine Überprüfung der Datumseingabe zu machen, welches nur mit mm/jjjj aussehen sollte,d.h es sollte als Eingabe nur z.B.
06/2006 oder 06.2006 möglich sein.
Hat jemand einen Tipp für mich?
Danke im voraus!
Tim
Antwort 1 von fedjo
Hallo TOmmyboy12,
ich hatte mal eine ähnliche Frage und diesen Cote erhalten, vielleicht hilft er dir weiter.
Eingabe in UserForm ist: TT.MM das aktuelle Jahr wird automatisch ergänzt.
Gruß
fedjo
Private Sub CommandButton4_Click()
Static Datum As Date
Debug.Print TextBox1.Text
If Len(TextBox1.Text) < 4 Then Exit Sub
If Len(TextBox1.Text) = 5 And InStr(TextBox1.Text, _
".") = 3 Then TextBox1.Text = TextBox1.Text & _
"." & Format(Now, "yyyy")
On Error GoTo Cdatefehler:
If Len(TextBox1.Text) = 10 And Datum = CDate(TextBox1.Text) Then Exit Sub
If Len(TextBox1.Text) = 10 Then
On Error Resume Next
Datum = CDate(TextBox1.Text)
Debug.Print Datum, "Err="; Err.Number
If Err = 0 Then
On Error GoTo 0
If Val(Left(TextBox1.Text, 2)) < 32 And Val(Left(TextBox1.Text, 2)) > 0 _
And Val(Mid(TextBox1.Text, 4, 2)) < 13 And Val(Mid(TextBox1, 4, 2)) > 0 _
And Right(TextBox1.Text, 4) = Format(Now, "yyyy") _
Then GoTo Cdateok
End If
Cdatefehler:
TextBox1.Text = ""
Err.Clear
Cdateok:
End If
Selection.AutoFilter Field:=1, Criteria1:=Datum
End Sub
ich hatte mal eine ähnliche Frage und diesen Cote erhalten, vielleicht hilft er dir weiter.
Eingabe in UserForm ist: TT.MM das aktuelle Jahr wird automatisch ergänzt.
Gruß
fedjo
Private Sub CommandButton4_Click()
Static Datum As Date
Debug.Print TextBox1.Text
If Len(TextBox1.Text) < 4 Then Exit Sub
If Len(TextBox1.Text) = 5 And InStr(TextBox1.Text, _
".") = 3 Then TextBox1.Text = TextBox1.Text & _
"." & Format(Now, "yyyy")
On Error GoTo Cdatefehler:
If Len(TextBox1.Text) = 10 And Datum = CDate(TextBox1.Text) Then Exit Sub
If Len(TextBox1.Text) = 10 Then
On Error Resume Next
Datum = CDate(TextBox1.Text)
Debug.Print Datum, "Err="; Err.Number
If Err = 0 Then
On Error GoTo 0
If Val(Left(TextBox1.Text, 2)) < 32 And Val(Left(TextBox1.Text, 2)) > 0 _
And Val(Mid(TextBox1.Text, 4, 2)) < 13 And Val(Mid(TextBox1, 4, 2)) > 0 _
And Right(TextBox1.Text, 4) = Format(Now, "yyyy") _
Then GoTo Cdateok
End If
Cdatefehler:
TextBox1.Text = ""
Err.Clear
Cdateok:
End If
Selection.AutoFilter Field:=1, Criteria1:=Datum
End Sub

