Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1208to1212
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
TextBox_Change() kürzen ?
amintire
Hallo alle zusammen,
wie kann ich folgenden Code besser kürzen?
Private Sub TextBox1_change()
CommandButton1.Enabled = TextBox1.Value  "" And TextBox2.Value  "" And TextBox3.Value  ""  _
And textbox4.Value  "" And textbox5.Value  ""
End Sub

Private Sub TextBox2_change()
CommandButton1.Enabled = TextBox1.Value  "" And TextBox2.Value  "" And TextBox3.Value  ""  _
And textbox4.Value  "" And textbox5.Value  ""
End Sub

Private Sub TextBox3_change()
CommandButton1.Enabled = TextBox1.Value  "" And TextBox2.Value  "" And TextBox3.Value  ""  _
And textbox4.Value  "" And textbox5.Value  ""
End Sub

Private Sub TextBox4_change()
CommandButton1.Enabled = TextBox1.Value  "" And TextBox2.Value  "" And TextBox3.Value  ""  _
And textbox4.Value  "" And textbox5.Value  ""
End Sub

Private Sub TextBox5_change()
CommandButton1.Enabled = TextBox1.Value  "" And TextBox2.Value  "" And TextBox3.Value  ""  _
And textbox4.Value  "" And textbox5.Value  ""
End Sub

Und zwar deshalb, weil CommandButton1 hat ca. 30 TextBox felder, CommandButton2 speichert auch 30 TextBox felder.
Das Problem, das speichern soll erst möglich sein wenn die TextBox Felder mit Daten sind, also leere TextBox Felder dann ist CommandButton nicht möglich zu klicken.
Wenn ich jetzt aber bis zu 200 TextBox Felder, jeden einzelnen mit diesen Change Ereignis schreiben muss, wäre das einwenig heftig. Geht es auch einfacher? Wenn ja wie?
Vielen Dank für Eure Hilfe.
Lieben Gruß
Amina

8
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: TextBox_Change() kürzen ?
26.04.2011 23:54:08
Uduuh
Hallo,
ich würde das in eine Function auslagern.
Private Sub TextBox1_Change()
CommandButton1.Enabled = fncCheckTxt(Array(1, 2, 3, 4, 5))
End Sub
Private Sub TextBox2_Change()
CommandButton1.Enabled = fncCheckTxt(Array(1, 2, 3, 4, 5))
End Sub
Private Sub TextBox3_Change()
CommandButton1.Enabled = fncCheckTxt(Array(1, 2, 3, 4, 5))
End Sub
Private Sub TextBox4_Change()
CommandButton1.Enabled = fncCheckTxt(Array(1, 2, 3, 4, 5))
End Sub
Private Sub TextBox5_Change()
CommandButton1.Enabled = fncCheckTxt(Array(1, 2, 3, 4, 5))
End Sub
Private Function fncCheckTxt(arrTxtBoxes) As Boolean
Dim vntTxtBox
fncCheckTxt = True
For Each vntTxtBox In arrTxtBoxes
fncCheckTxt = fncCheckTxt And Controls("TextBox" & vntTxtBox)  ""
Next
End Function
Gruß aus’m Pott
Udo

Anzeige
AW: TextBox_Change() kürzen ?
27.04.2011 20:55:59
amintire
Hallo Tino,
funktioniert das auch als Klasse wenn die TextBoxen in einer UserForm und nicht in der Tabelle sind ?
Lieben Gruß
Amina
AW: geht auch...
27.04.2011 21:24:18
amintire
Hallo Tino,
danke für deine Beispielmappe, aber irgendwie ist das auch nicht weniger Code. ;)
Aber ist aufjedenfall gut zu wissen wie es sonst auch funktionieren könnte.
Lieben Gruß
und schönen Abend
Amina
Anzeige
Bei 200 Textboxen? War nur ein Vorschlag oT.
27.04.2011 21:52:15
Tino
AW: Bei 200 Textboxen? War nur ein Vorschlag oT.
27.04.2011 22:56:37
amintire
Hallo Tino,
beschwere mich doch nicht ;) Bin doch dankbar für deine Hilfe und Vorschläge.
Werde es evtl doch hernehmen ;))
Aufjedenfall vielen vielen lieben Dank
Lieben Gruß Amina
so war es auch nicht gemeint, ...
28.04.2011 11:39:43
Tino
Hallo,
ich kann mir nur nicht vorstellen dass Deine Variante bei 200 Textboxen
in etwa genau so viel Code benötigt.
Gruß Tino

179 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige