AW: Zurück in TextBox
04.01.2021 16:01:40
Mullit
Hallo,
probier mal, der erste Code sind Deine angepassten Exit-Events aus der Form, der zweite Code gehört in ein Standard-Modul:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Bereich As Range
If NoEX Then Exit Sub 'Für das vorzeitige Abbrechen
If TextBox1 <> "" Then
If Not IsNumeric(TextBox1.Text) And TextBox1 = "" Then
MsgBox "Bitte eine Zahl mit 6 Ziffern eintragen!", vbInformation
Cancel = True
With TextBox1
.Text = ""
.SetFocus
End With
ElseIf Len(TextBox1.Text) <> 6 Then
MsgBox "Bitte eine Zahl mit 6 Ziffern eintragen!", vbInformation
Cancel = True
With TextBox1
.Text = ""
.SetFocus
End With
Else
Set Bereich = ActiveSheet.Range("S7:S44").Find(TextBox1, lookat:=xlWhole)
If Bereich Is Nothing Then
Set TextBox = TextBox2
Call Application.OnTime(EarliestTime:=Now, Procedure:="SetFocus_TextBox")
Call Preis_Ein
Else
MsgBox "Rechnungsnummer " & TextBox1 & " bereits vorhanden!", vbInformation
TextBox1 = ""
End If
End If
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim strPreis As String
Dim lngZellen As Long
If NoEX Then Exit Sub 'Für das vorzeitige Abbrechen
strPreis = TextBox2.Text
If strPreis <> "" Then
If Not IsNumeric(strPreis) Then
MsgBox "Bitte einen Preis eintragen!", vbInformation
Cancel = True
With TextBox2
.Text = ""
.SetFocus
End With
Else
strPreis = Format(strPreis, "#,##0.00")
On Error Resume Next
lngZellen = ActiveSheet.Range("S7:S44").SpecialCells(xlCellTypeBlanks).Cells(1).Row
On Error GoTo 0
If lngZellen > 0 Then
TextBox2 = ""
ActiveSheet.Cells(lngZellen, 19) = TextBox1.Value
ActiveSheet.Cells(lngZellen, 20) = strPreis
With TextBox1
.Text = ""
Set TextBox = TextBox1
Call Application.OnTime(EarliestTime:=Now, Procedure:="SetFocus_TextBox")
End With
Else
MsgBox "Alle Zeilen voll!"
Unload Me
End If
End If
End If
End Sub
Option Explicit
Option Private Module
Private lobjTextBox As MSForms.TextBox
Public Sub SetFocus_TextBox()
If Not lobjTextBox Is Nothing Then
Call lobjTextBox.SetFocus
Set lobjTextBox = Nothing
End If
End Sub
Public Property Set TextBox(ByRef probjTextBox As MSForms.TextBox)
Set lobjTextBox = probjTextBox
End Property
VBA/HTML - CodeConverter für Office-Foren
AddIn für Excel/Word 2000-2010 - komplett in VBA geschrieben von Lukas Mosimann
Projektbetreuung durch mumpel
Code erstellt und getestet in Office 14
Gruß, Mullit