TextBox1.SetFocus in UF geht nicht
05.02.2021 15:19:42
Peter
ich habe ein kleines Problem mit TextBox1.SetFocus.
Ich befülle die UF mit nachstehendem Code der TabIndex = 0, die Aktiverreihenfolge für TB1 ist an erster Stelle:
Private Sub UserForm_Initialize()
Dim wb As Workbook
Dim wksTB1 As Worksheet
Dim Zeile% 'erforderlich für ListBox1
Dim avntValues As Variant 'benötigt für ComboBox3
Dim ialngIndex As Long 'benötigt für ComboBox3
Dim aRow, I As Long 'benötigt für ComboBox1
'Anfang Bildschirmgroesse
Application.WindowState = xlMaximized
With Me
.Height = Application.Height
.Width = Application.Width
End With
'Ende Bildschirmgroesse
Set wb = ThisWorkbook
Set wksTB1 = wb.Worksheets("Tabelle1")
'Auswahl Grund der Eintragung
With ComboBox2
.RowSource = "=Hilfstabelle!$C$2:$C$3"
End With
'Ende ComboBox2
'Anfang befüllen ListBox1
With ListBox1
Zeile = wksTB1.Cells(Rows.Count, 1).End(xlUp).Row
.RowSource = "Tabelle1!A1:H" & Zeile
.ColumnHeads = False
.ColumnCount = 7
.ColumnWidths = "3,0cm;4,1cm;2,5cm;3,1cm;2,0cm;2,0cm;2,0cm"
'.ListIndex = Zeile - 1 'markiert die letzte Zeile nicht erforderlich
End With
'Ende ListBox1 füllen
'Anfang - letzten Eintrag in Listbox1 anzeigen
With ListBox1
If .ListCount > 0 Then
.TopIndex = .ListCount
End If
End With
'Ende - letzten Eintrag in Listbox1 anzeigen
'Ende befüllen ListBox1
'Beginn ComboBox3
'vorhandener Anfangbestand Briefmarkenwerte
With Worksheets("Berechnungstabelle")
avntValues = .Range(.Cells(2, 1), .Cells( _
.Cells(.Rows.Count, 1).End(xlUp).Row, 14)).Value2
End With
With ComboBox3
For ialngIndex = 1 To UBound(avntValues)
If avntValues(ialngIndex, 1) > "0" Then 'zeigt nur die Werte an die über "0" _
sind - "" zeigt alle Werte an
Call .AddItem(Format(avntValues(ialngIndex, 1), "#0.00"))
.List(.ListCount - 1, 1) = Format(avntValues(ialngIndex, 14), "0")
End If
Next
End With
'Ende ComboBox3
'Anfang benötigt für ComboBox1 füllen
Call ComboBox1_fuellen
Me.Label37.Visible = True
Me.Label37.Caption = ""
CommandButton8.Visible = False
If ComboBox1.Value = "neue Buchung hinzufügen" Then
' If ComboBox1.ListIndex = 0 Then
Label37.Caption = "für neue Buchung bitte u. a. Felder ausfüllen - Button ""Buchen"" _
drücken oder" _
& vbLf & "bitte Buchung auswählen, Daten ändern - Button Andern drücken _
oder" _
& vbLf & "Abbruch bzw. Formular beenden!"
With TextBox1
.SetFocus
.SelStart = 0
End With
End If
'Ende benötigt für ComboBox1 füllen
Me.TextBox11.Visible = False
'Anfang bei erforderlich für Passwort bei Service
CommandButton23.Enabled = False
CommandButton24.Visible = False
CommandButton25.Visible = False
CommandButton30.Visible = False
CommandButton31.Visible = False
Me.TextBox17.PasswordChar = "*"
'Ende bei erforderlich für Passwort bei Service
End Sub
Was muss ich bitte ändern, damit die TextBox1 beim Öffnen den Focus erhält.UserForm_Activate enthält derzeit nichts.
Gruss
Peter