Supportnet Computer
Planet of Tech

Supportnet / Forum / Tabellenkalkulation

Userform / Textfeld / Setfocus





Frage

Hallo Excelgemeinde... komme nach vielen Versuchen nicht zum gewünschten Ergebnis: EinTabellenblatt ist komplett geschützt, und soll ausschließlich von einer Userform bedient werden. Es geht hierbei um die Textfelder..... Wenn ich zwei im Wechsel als Eingabe nutze, so ist es kein Problem diesen auch abwechselnt den Focus zuzuweisen. Es gibt aber noch ein Textfeld, in dem auch mehrer Eingaben hintereinander gemacht werden sollen. Nur schaffe ich es nicht, das nach der Return-Taste sich der Cursor wieder für die nächste Eingabe im Textfeld zeigt. Hier der Code: [code] Private Sub TxtNotiz_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) ' Die Variable aks beginnt bei der ersten Eingabe mit 0.... ' sie wird bei Opt5 auf Null gesetzt If KeyCode = 13 Then If Opt5.Value = False Then ' Der Bereich ist für Einzeleingaben Else If aks = 0 Then Sheets("Eingabe").Txt11.Value = TxtNotiz.Value If aks = 1 Then Sheets("Eingabe").Txt12.Value = TxtNotiz.Value If aks = 2 Then Sheets("Eingabe").Txt13.Value = TxtNotiz.Value If aks = 3 Then Sheets("Eingabe").Txt21.Value = TxtNotiz.Value If aks = 4 Then Sheets("Eingabe").Txt22.Value = TxtNotiz.Value If aks = 5 Then Sheets("Eingabe").Txt23.Value = TxtNotiz.Value If aks = 6 Then Sheets("Eingabe").Txt31.Value = TxtNotiz.Value If aks = 7 Then Sheets("Eingabe").Txt32.Value = TxtNotiz.Value If aks = 8 Then Sheets("Eingabe").Txt33.Value = TxtNotiz.Value If aks = 9 Then Sheets("Eingabe").Txt41.Value = TxtNotiz.Value If aks = 10 Then Sheets("Eingabe").Txt42.Value = TxtNotiz.Value If aks = 11 Then Sheets("Eingabe").Txt43.Value = TxtNotiz.Value 'If TxtNotiz.Value = "" Then Opt5.Value = False aks = aks + 1 If aks = 12 Then Sheets("Eingabe").TxtNotiz.Enabled = False If aks = 1 Then Frame3.Caption = "Zweite Zeile für Pos 1" If aks = 2 Then Frame3.Caption = "Dritte Zeile für Pos 1" If aks = 3 Then Frame3.Caption = "Erste Zeile für Pos 2" If aks = 4 Then Frame3.Caption = "Zweite Zeile für Pos 2" If aks = 5 Then Frame3.Caption = "Dritte Zeile für Pos 2" If aks = 6 Then Frame3.Caption = "Erste Zeile für Pos 3" If aks = 7 Then Frame3.Caption = "Zweite Zeile für Pos 3" If aks = 8 Then Frame3.Caption = "Dritte Zeile für Pos 3" If aks = 9 Then Frame3.Caption = "Erste Zeile für Pos 4" If aks = 10 Then Frame3.Caption = "Zweite Zeile für Pos 4" If aks = 11 Then Frame3.Caption = "Dritte Zeile für Pos 4" '----------- ab Hier soll Focus wieder auf's Textfeld-------- TxtNotiz.Text = "" TxtNotiz.SetFocus End If End If Sheets("Eingabe").Protect End Sub [/code] Er landet trotz > Txtnotiz.setfocus < immer auf einer(der gleichen) Schaltfläche. Voraussetzungen: Win XP / Excel2003 Mir fehlen einfach die Ereignisse GotFokus und Lostfokus.... ich meine, unter Excel97 und/ oder Excel2000 gab es diese noch. Was kann da als Ersatz fungieren? Ratlose Grüße Andreas

Antwort 1 von Hajo_Zi

Hallo Andreas,

ich habe Dein Beispiel jetzt nicht nachgebaut, die Zeit zur Erstellung hast Du ja schon investiert.
Benutze das Exit Ereignis und mt Cancel=True, bleibt der Focus in der Textbox.

Gruß Hajo

Antwort 2 von Kauz

Hallo Hajo...
Hab Deinen Tipp probiert:

Textfeld steckte in einem Frame... nun ist es direkt auf der Userform. (Damit es einfacher wird)
Habe in den Ereignissen <Enter> und <Exit> eine msgbox eingebaut...
Dannach zu urteilen, bleibt der Fokus auf dem Textfeld.

Es wird allerdings kein Cursor angezeigt, und eine Eingabe zu tätigen ist nicht möglich.

Hast Du vielleicht noch eine Idee?

Gruß
Andreas

Antwort 3 von Hajo_Zi

Hallo Andreas,

ich habe es gerade getestet ohne Probleme
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox 1
Cancel = True
End Sub
Ein Nachbau sieht aber meist anders aus als das Original.

Gruß Hajo

Antwort 4 von Kauz

Hallo Hajo,
dann werde ich mal einen Rückbau vornehmen:

Ich erstelle eine neue Tabelle nur mit den für diese Funktion relevanten Elementen.
Vielleicht ergibt sich ja ein Problem an einer ganz anderen Stelle?

Also Schritt für Schritt erweitern, und schauen ab wann sich dieser Effekt einstellt.

Ich bedanke mich erstmal für Deine Bemühungen.....

Evtl. frag ich nochmal nach....

Gruß
Andreas

Ich möchte kostenlos eine Frage an die Mitglieder stellen:


Ähnliche Themen:


Suche in allen vorhandenen Beiträgen: