Option
Explicit
Option
Compare Text
Private
Const
iCONST_ANZAHL_EINGABEFELDER
As
Integer
= 5
Private
Const
lCONST_STARTZEILENNUMMER_DER_TABELLE
As
Long
= 2
Private
Sub
CommandButton_4_Click()
Unload
Me
End
Sub
Private
Sub
CommandButton1_Click()
Call
EINTRAG_ANLEGEN
End
Sub
Private
Sub
CommandButton2_Click()
Call
EINTRAG_LOESCHEN
End
Sub
Private
Sub
CommandButton3_Click()
Call
EINTRAG_SPEICHERN
End
Sub
Private
Sub
CommandButton4_Click()
Unload
Me
End
Sub
Private
Sub
ListBox1_Click()
Call
EINTRAG_LADEN_UND_ANZEIGEN
End
Sub
Private
Sub
UserForm_Activate()
If
ListBox1.ListCount > 0
Then
ListBox1.ListIndex = 0
End
Sub
Private
Sub
UserForm_Initialize()
Call
LISTE_LADEN_UND_INITIALISIEREN
End
Sub
Private
Sub
LISTE_LADEN_UND_INITIALISIEREN()
Dim
lZeile
As
Long
Dim
lZeileMaximum
As
Long
Dim
i
As
Integer
For
i = 1
To
iCONST_ANZAHL_EINGABEFELDER
Me
.Controls(
"TextBox"
& i) =
""
Me
.Controls(
"Checkbox"
& i) =
""
Next
i
ListBox1.Clear
ListBox1.ColumnCount = 4
ListBox1.ColumnWidths =
"0;;;"
lZeileMaximum = Tabelle1.UsedRange.Rows.Count
For
lZeile = lCONST_STARTZEILENNUMMER_DER_TABELLE
To
lZeileMaximum
If
IST_ZEILE_LEER(lZeile) =
False
Then
ListBox1.AddItem lZeile
ListBox1.List(ListBox1.ListCount - 1, 1) =
CStr
(Tabelle1.Cells(lZeile, 1).Text)
ListBox1.List(ListBox1.ListCount - 1, 2) =
CStr
(Tabelle1.Cells(lZeile, 2).Text)
ListBox1.List(ListBox1.ListCount - 1, 3) =
CStr
(Tabelle1.Cells(lZeile, 3).Text)
End
If
Next
lZeile
End
Sub
Private
Sub
EINTRAG_LADEN_UND_ANZEIGEN()
Dim
lZeile
As
Long
Dim
i
As
Integer
For
i = 1
To
iCONST_ANZAHL_EINGABEFELDER
Me
.Controls(
"TextBox"
& i) =
""
Next
i
If
ListBox1.ListIndex >= 0
Then
lZeile = ListBox1.List(ListBox1.ListIndex, 0)
For
i = 1
To
iCONST_ANZAHL_EINGABEFELDER
Me
.Controls(
"TextBox"
& i) =
CStr
(Tabelle1.Cells(lZeile, i).Text)
Next
i
End
If
End
Sub
Private
Sub
EINTRAG_SPEICHERN()
Dim
lZeile
As
Long
Dim
i
As
Integer
If
ListBox1.ListIndex = -1
Then
Exit
Sub
lZeile = ListBox1.List(ListBox1.ListIndex, 0)
For
i = 1
To
iCONST_ANZAHL_EINGABEFELDER
Tabelle1.Cells(lZeile, i) =
Me
.Controls(
"TextBox"
& i)
Next
i
ListBox1.List(ListBox1.ListIndex, 1) = TextBox1
ListBox1.List(ListBox1.ListIndex, 2) = Textbox2
ListBox1.List(ListBox1.ListIndex, 3) = TextBox3
End
Sub
Private
Sub
EINTRAG_LOESCHEN()
Dim
lZeile
As
Long
If
ListBox1.ListIndex = -1
Then
Exit
Sub
If
MsgBox(
"Sie möchten den markierten Datensatz wirklich löschen?"
, _
vbQuestion + vbYesNo,
"Sicherheitsabfrage!"
) = vbYes
Then
lZeile = ListBox1.List(ListBox1.ListIndex, 0)
Tabelle1.Rows(
CStr
(lZeile &
":"
& lZeile)).Delete
ListBox1.RemoveItem ListBox1.ListIndex
End
If
End
Sub
Private
Sub
EINTRAG_ANLEGEN()
Dim
lZeile
As
Long
lZeile = lCONST_STARTZEILENNUMMER_DER_TABELLE
Do
While
IST_ZEILE_LEER(lZeile) =
False
lZeile = lZeile + 1
Loop
Tabelle1.Cells(lZeile, 1) =
CStr
(
"Neuer Eintrag"
& lZeile)
ListBox1.AddItem lZeile
ListBox1.List(ListBox1.ListCount - 1, 1) =
CStr
(
"Neuer Eintrag"
& lZeile)
ListBox1.List(ListBox1.ListCount - 1, 2) =
""
ListBox1.List(ListBox1.ListCount - 1, 3) =
""
ListBox1.ListIndex = ListBox1.ListCount - 1
MultiPage1.Value = 0
TextBox1.SetFocus
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1)
End
Sub
Private
Function
IST_ZEILE_LEER(
ByVal
lZeile
As
Long
)
As
Boolean
Dim
i
As
Long
Dim
sTemp
As
String
sTemp =
""
For
i = 1
To
iCONST_ANZAHL_EINGABEFELDER
sTemp = sTemp & Trim(
CStr
(Tabelle1.Cells(lZeile, i).Text))
Next
i
If
Trim(sTemp) =
""
Then
IST_ZEILE_LEER =
True
Else
IST_ZEILE_LEER =
False
End
If
End
Function