AW: TextBox Formatierung beim speichern
26.03.2022 12:47:11
Alwin
Hallo Hardy,
anbei mal schnell einiges angepasst. Momentan keine Garantie auf Fehlerfreiheit. Da ich es in 5 min schnell mal einiges angepasst habe.
Private Sub LISTE_LADEN_UND_INITIALISIEREN()
Dim lZeile As Long
Dim lZeileMaximum As Long
Dim i As Integer
'Alle TextBoxen leer machen
For i = 1 To iCONST_ANZAHL_EINGABEFELDER
Me.Controls("TextBox" & i) = ""
Next i
ListBox1.Clear 'Liste leeren
'Anzahl Spalten einrichten
'wobei Spalte 1: Zeilennummer des Datensatzes
ListBox1.ColumnCount = 10
'Spaltenbreiten der Liste anpassen (0=ausblenden, nichts=automatisch)
'";;;usw."
ListBox1.ColumnWidths = "0;125;90;100;100;120;80;80;120;80"
'Feste Breiten: ListBox1.ColumnWidths = "0;50;100;100"
'Um eine Schleife für alle Datensätze zu erhalten benötigen wir die letzte verwendete Zeile
lZeileMaximum = Tabelle10.UsedRange.Rows.Count 'Benutzer Bereich auslesen
For lZeile = lCONST_STARTZEILENNUMMER_DER_TABELLE To lZeileMaximum
'Nur wenn die Zeile benutzt / nicht leer ist, zeigen wir etwas an:
If IST_ZEILE_LEER(lZeile) = False Then
'Spalte 1 der Liste mit der Zeilennummer füllen
ListBox1.AddItem lZeile
'Spalten 2 bis .. der Liste füllen
ListBox1.List(ListBox1.ListCount - 1, 1) = CStr(Tabelle10.Cells(lZeile, 2).Text) ' name
ListBox1.List(ListBox1.ListCount - 1, 2) = CStr(Tabelle10.Cells(lZeile, 3).Text) ' Typ
ListBox1.List(ListBox1.ListCount - 1, 3) = CStr(Tabelle10.Cells(lZeile, 4).Text) ' Wochentag
ListBox1.List(ListBox1.ListCount - 1, 4) = CStr(Tabelle10.Cells(lZeile, 5).Text) ' von
ListBox1.List(ListBox1.ListCount - 1, 5) = CStr(Tabelle10.Cells(lZeile, 6).Text) ' bis
ListBox1.List(ListBox1.ListCount - 1, 6) = CStr(Tabelle10.Cells(lZeile, 7).Text) ' dauer
ListBox1.List(ListBox1.ListCount - 1, 7) = CStr(Tabelle10.Cells(lZeile, 8).Text) ' Fzg Nr
ListBox1.List(ListBox1.ListCount - 1, 8) = CStr(Format(Tabelle10.Cells(lZeile, 9), "#,##0.00 ")) ' Pauschale
ListBox1.List(ListBox1.ListCount - 1, 9) = CStr(Format(Tabelle10.Cells(lZeile, 10), "#,##0.00 ")) ' S-Zuschlag
End If
Next lZeile
End Sub
Private Sub EINTRAG_LADEN_UND_ANZEIGEN()
Dim lZeile As Long
Dim i As Integer
'Eingabefelder resetten
For i = 1 To iCONST_ANZAHL_EINGABEFELDER
Me.Controls("TextBox" & i) = ""
Next i
'Nur wenn ein Eintrag selektiert/markiert ist
If ListBox1.ListIndex >= 0 Then
'Die Zeilennummer des Datensatzes steht in der ersten ausgeblendeten Spalte der Liste,
'somit können wir direkt zugreifen.
lZeile = ListBox1.List(ListBox1.ListIndex, 0)
'For i = 1 To iCONST_ANZAHL_EINGABEFELDER
'Me.Controls("TextBox" & i) = CStr(Tabelle10.Cells(lZeile, i).Text)
'Next i
With Tabelle10
TextBox1 = CStr(CDbl(.Cells(lZeile, 1)))
TextBox2 = CStr(.Cells(lZeile, 2).Text)
TextBox3 = CStr(.Cells(lZeile, 3).Text)
TextBox4 = CStr(Format(.Cells(lZeile, 4), "ddd"))
TextBox5 = CStr(Format(.Cells(lZeile, 5), "DD.MM.yyyy hh:mm:ss"))
TextBox6 = CStr(Format(.Cells(lZeile, 6), "DD.MM.yyyy hh:mm:ss"))
TextBox7 = CStr(Format(.Cells(lZeile, 7), "hh:mm"))
TextBox8 = CStr(.Cells(lZeile, 8).Text)
TextBox9 = CStr(Format(.Cells(lZeile, 9), "#,##0.00 "))
TextBox10 = CStr(Format(.Cells(lZeile, 10), "#,##0.00 "))
End With
End If
End Sub
Private Sub EINTRAG_SPEICHERN()
Dim lZeile As Long
Dim i As Integer
' Formate werden leider als Text gespeichert
TextBox1 = CDbl(TextBox1) ' Personalnr als Zahl
' TextBox5 ' von tt.mm.jjjj hh.mm
' TextBox6 ' bis tt.mm.jjjj hh.mm
' TextBox7 ' Dauer hh.mm
TextBox9 = Format(Me.TextBox9, "# ##0.00 ") ' Pauschalsumme
TextBox10 = Format(Me.TextBox10, "# ##0.00 ") ' Sonntagszuschlag
'Wenn kein Datensatz in der ListBox markiert wurde, wird die Routine beendet
If ListBox1.ListIndex = -1 Then Exit Sub
'Zum Speichern benötigen wir die Zeilennummer des ausgewählten Datensatzes
lZeile = ListBox1.List(ListBox1.ListIndex, 0)
'For i = 1 To iCONST_ANZAHL_EINGABEFELDER
'Tabelle10.Cells(lZeile, i) = Me.Controls("TextBox" & i)
'Next i
With Tabelle10
.Cells(lZeile, 1) = CDbl(TextBox1)
.Cells(lZeile, 2) = TextBox2
.Cells(lZeile, 3) = TextBox3
.Cells(lZeile, 4) = TextBox4
.Cells(lZeile, 5) = CDate(Format(TextBox5, "DD.MM.yyyy hh:mm:ss"))
.Cells(lZeile, 6) = CDate(Format(TextBox6, "DD.MM.yyyy hh:mm:ss"))
.Cells(lZeile, 7) = Format(TextBox7, "hh:mm")
.Cells(lZeile, 8) = TextBox8
If TextBox9 = "" Then
.Cells(lZeile, 9) = TextBox9
Else
.Cells(lZeile, 9) = CDbl(Format(TextBox9, "# ##0.00 "))
End If
If TextBox10 = "" Then
.Cells(lZeile, 10) = TextBox10
Else
.Cells(lZeile, 10) = CDbl(Format(TextBox10, "# ##0.00 "))
End If
End With
'Der Benutzer könnte die angezeigten Werte in der Liste geändert haben,
'daher aktualisieren wir den ausgewählten Eintrag entsprechend.
ListBox1.List(ListBox1.ListIndex, 1) = TextBox2 ' Name Text
ListBox1.List(ListBox1.ListIndex, 2) = TextBox3 ' Typ Text
ListBox1.List(ListBox1.ListIndex, 3) = TextBox4 ' Wochentag Text
ListBox1.List(ListBox1.ListIndex, 4) = TextBox5 ' von TT.MM.JJJJ HH.MM
ListBox1.List(ListBox1.ListIndex, 5) = TextBox6 ' Bis TT.MM.JJJJ HH.MM
ListBox1.List(ListBox1.ListIndex, 6) = TextBox7 ' Dauer in Std. Minuten HH.MM
ListBox1.List(ListBox1.ListIndex, 7) = TextBox8 ' Fahrzeugnr Text
ListBox1.List(ListBox1.ListIndex, 8) = TextBox9 ' Pauschale
ListBox1.List(ListBox1.ListIndex, 9) = TextBox10 ' Sonntagszuschlag
End Sub
Gruß Uwe