J
jogamen
Hi i have folowing code and the problem is than when cell is empty the code
should move focus to the textbox1 with error mesege but instead of that it is
running again the code for textbox2_enter. Any idea what is the problem?
Thank you
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
udaje = TextBox1.Text
dlzka = TextBox1.TextLength
If dlzka < 9 Then GoTo line1
kontrola = IsNumeric(udaje)
If kontrola = False Then GoTo line1 Else GoTo line2
line1:
TextBox1.SetFocus
MsgBox " Nebolo zadané správne ÄÃslo! Tu možeÅ¡ zadaÅ¥ len 9 miestne
ÄÃslo.", vbCritical, " CHYBA ÄŒÃSLA TOVARU"
Cancel = True
Exit Sub
line2:
End Sub
Private Sub TextBox2_Enter()
If TextBox1.Text = "" Then GoTo line1 Else GoTo line2
line1:
TextBox1.SetFocus
MsgBox "Nebol zadaný Äiarový kód!", vbCritical, " Chyba v ÄÃsle tovaru"
Exit Sub
line2:
Workbooks.Open "\\Alpha\quort_prenos\Ciselnik skladu.xls"
Workbooks("Ciselnik skladu.xls").Activate
Worksheets("Udaje").Select
vyhladat = TextBox1.Text
riadok = 1
Cells(riadok, 1).Select
kontrola = Cells(riadok, 1).Text
Do Until kontrola = vyhladat
riadok = riadok + 1
Cells(riadok, 1).Select
kontrola = Cells(riadok, 1).Text
If Cells(riadok, 1).Text = "" Then GoTo line3
Loop
Label1.Caption = Cells(riadok, 2).Text
UserForm1.Caption = UserForm1.Caption & " - " & Cells(riadok, 2).Text
GoTo lastline
line3:
TextBox1.SetFocus
MsgBox " Takýto tovar sa nenachádza v skladovej evidencii! Skontroluj
si ÄÃslo tovaru.", vbInformation, " POZOR"
lastline:
Workbooks("Ciselnik skladu.xls").Close SaveChanges:=False
Exit Sub
End Sub
should move focus to the textbox1 with error mesege but instead of that it is
running again the code for textbox2_enter. Any idea what is the problem?
Thank you
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
udaje = TextBox1.Text
dlzka = TextBox1.TextLength
If dlzka < 9 Then GoTo line1
kontrola = IsNumeric(udaje)
If kontrola = False Then GoTo line1 Else GoTo line2
line1:
TextBox1.SetFocus
MsgBox " Nebolo zadané správne ÄÃslo! Tu možeÅ¡ zadaÅ¥ len 9 miestne
ÄÃslo.", vbCritical, " CHYBA ÄŒÃSLA TOVARU"
Cancel = True
Exit Sub
line2:
End Sub
Private Sub TextBox2_Enter()
If TextBox1.Text = "" Then GoTo line1 Else GoTo line2
line1:
TextBox1.SetFocus
MsgBox "Nebol zadaný Äiarový kód!", vbCritical, " Chyba v ÄÃsle tovaru"
Exit Sub
line2:
Workbooks.Open "\\Alpha\quort_prenos\Ciselnik skladu.xls"
Workbooks("Ciselnik skladu.xls").Activate
Worksheets("Udaje").Select
vyhladat = TextBox1.Text
riadok = 1
Cells(riadok, 1).Select
kontrola = Cells(riadok, 1).Text
Do Until kontrola = vyhladat
riadok = riadok + 1
Cells(riadok, 1).Select
kontrola = Cells(riadok, 1).Text
If Cells(riadok, 1).Text = "" Then GoTo line3
Loop
Label1.Caption = Cells(riadok, 2).Text
UserForm1.Caption = UserForm1.Caption & " - " & Cells(riadok, 2).Text
GoTo lastline
line3:
TextBox1.SetFocus
MsgBox " Takýto tovar sa nenachádza v skladovej evidencii! Skontroluj
si ÄÃslo tovaru.", vbInformation, " POZOR"
lastline:
Workbooks("Ciselnik skladu.xls").Close SaveChanges:=False
Exit Sub
End Sub