online 1
gast (50)

/ Forum / Tabellenkalkulation

TabellenkalkulationTabellenkalkulation

Fragevon Klapptnicht vom 30.06.2021, 16:55 Options

Lösung

Textfeld Userform als Datum formatieren

Hallo,

also, ich habe ein Textfeld in einer Userform, in das einfach ein Datum eingegeben werden soll, z.b. 01072009.

Kriegt man das irgendwie hin, das man das Feld nach Update so formatiert, das es wie n Datum aussieht: 01.07.2009, sprich mit Punkten ??

Der Befehl
TextBox7 = Format(TextBox7, "DD.MM.YYYY")

zeigt mir immer einen Überlauffehler, Laufzeitfehler 6 an ..

Hat jemand eine Idee ??

Danke schon mal


Antwort schreiben

Antwort 1 von fedjo vom 30.06.2021, 18:28 Options

Hallo Klapptnicht,
einfach das Datum in die Textbox ohne Punkt eingeben.

Gruß
fedjo

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If InStr(1, TextBox1, ".") Then
MsgBox "Bitte datum ohne Punkte eingeben!", 64, "Hinweis..."
Exit Sub
Else
If IsNumeric(TextBox1) Then
If IsDate(Format(TextBox1, "00-00-0" & IIf(Len(TextBox1) > 6, "000", "0"))) Then
UserForm1.TextBox1 = CDate(Format(TextBox1, "00-00-0" & IIf(Len(TextBox1) > 6, "000", "0")))
End If
End If
End If
End Sub

Antwort 2 von Hajo_Zi vom 30.06.2021, 19:10 OptionsLösung

Lösung
Hallo Nick,

Option Explicit
Dim BoEnter As Boolean

Private Sub TextBox6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
' erstellt von *xxxxxxxxx*@web.de Stand 01.08.03
' Datumseingabe 01.01.03;1.1.03 oder komlettes Jahr
' Eingabe des Tages und des Monat zweistellig werden die Punkte automatisch gesetzt
' sie können nur gelöscht durch markierung des punktes und der Zahl davor
' Buchstaben werden ausgeschlossen, nur Zahlen und Punkt
' die Überprüfung ob Datum erfolgt in Private Sub TextBox6_AfterUpdate()
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc(".")
If Len(TextBox6) = 0 Then
KeyAscii = 0
Else
If Len(TextBox6) - Len(Application.Substitute(TextBox6, ".", "")) = 2 Then
KeyAscii = 0
ElseIf Len(TextBox6) > 1 Then
If Mid(TextBox6, Len(TextBox6), 1) = "." Then KeyAscii = 0
Else
KeyAscii = Asc(".")
End If
End If
Case Else
KeyAscii = 0
End Select
End Sub

Private Sub TextBox6_Change()
If BoEnter = True Then Exit Sub
If Len(TextBox6) = 2 Then
If InStr(TextBox6, ".") = 0 And BoEnter = False Then TextBox6 = TextBox6 & "."
ElseIf Len(TextBox6) = 5 Then
If Len(TextBox6) - Len(Application.Substitute(TextBox6, ".", "")) < 2 Then
TextBox6 = TextBox6 & "."
End If
End If
End Sub

Private Sub TextBox6_AfterUpdate()
BoEnter = True
If Right(TextBox6, 1) = "." Then TextBox6 = Mid(TextBox6, 1, Len(TextBox6) - 1)
' Jahreszahl vom aktuellen Jahr ergänzen falls nicht vorhanden
If Len(TextBox6) - Len(Application.Substitute(TextBox6, ".", "")) = 1 Then
TextBox6 = TextBox6 & "." & Year(Date)
End If
If IsDate(TextBox6.Text) Then
If Format(CDate(TextBox6.Value), "dd.mm.yy") <> TextBox6 Then
MsgBox "Das Datum wurde übersetzt"
End If
TextBox6 = Format(CDate(TextBox6.Value), "dd.mm.yy")
Else
TextBox6 = ""
End If
BoEnter = False
End Sub

Gruß hajo


  • *Threadedit* 30.06.2009, 19:24:30
    Admininfo: Persönliche Daten gelöscht, siehe FAQ 5, #5
  • Antwort 3 von Klapptnicht vom 30.06.2021, 21:09 Options

    Hi,

    ich gebe das Datum ohne Punkt ein: 01072009, also Format ttmmjjjj.
    und das dann umsetzen in tt.mm.jjjj

    Die Antworten klappen nur mit Eingabe mit "." (Punkt) ...

    Hat einer noch Vorschläge ??

    Danke schon mal ...

    Antwort 4 von Hajo_Zi vom 30.06.2021, 21:24 Options

    Hallo Nick,

    in meiner Lösung brauchen kein Punkte eingegeben werden, die werden automatisch erzeugt.

    Gruß Hajo

    Antwort 5 von Klapptnicht vom 01.07.2021, 13:35 Options

    Hi Hajo,

    jau, jetzt klappst, Schreibfehler drin gehabt :-((

    Super, danke :-)))))))))))))

    funktioniert top ...

    Ähnliche Themen

    Auswahlfeld in Userform
    jackson84  24.01.2008 - 85 Hits - 30 Antworten

    von einem Datum auf ein Datum runden
    TheBluebird  07.03.2008 - 77 Hits - 4 Antworten

    Userform / Textfeld / Setfocus
    Kauz  05.05.2008 - 12 Hits - 4 Antworten

    Userform: Textfeld soll Inhalt behalten
    Kauz  23.07.2008 - 12 Hits - 4 Antworten

    Datum nach übernahme aus UserForm in Zahl umwandeln
    BenjaminM  12.01.2009 - 151 Hits - 12 Antworten

    Hinweis

    Diese Frage ist schon etwas älter, Sie können daher nicht mehr auf sie antworten. Sollte Ihre Frage noch nicht gelöst sein, stellen Sie einfach eine neue Frage im Forum..

    Neue Einträge

    Version: supportware 1.9.150 / 10.06.2022, Startzeit:Mon Jan 26 16:59:01 2026