Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus problem
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus problem
Which sub is running, jogamen? If you're not sure, try putting a MsgBox at
the beginning of each Sub: MsgBox "Entering TextBox1_Exit" 'or whichever sub name By the way, I'm not one of those people who say GoTos are ALWAYS bad, but it semes to me your first Sub would be simpler in this form: Private Sub TextBox1_Exit(ByVal Cancel _ As MSForms.ReturnBoolean) If TextBox1.TextLength = 9 And _ IsNumeric(TextBox1.Text) Then Exit Sub TextBox1.SetFocus MsgBox " Nebolo zadané správne č*slo! Tu " & _ "možeš zadať len 9 miestne č*slo.", vbCritical, _ " CHYBA ČÍSLA TOVARU" Cancel = True End Sub --- "jogamen" wrote: 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus problem
Hi Bob,
the problem is with code in TextBox2_Enter. If the the code dont find the requested value it should go to line3, msgbox should appear, move focus to the textbox1 and exit/stop sub. "Bob Bridges" wrote: Which sub is running, jogamen? If you're not sure, try putting a MsgBox at the beginning of each Sub: MsgBox "Entering TextBox1_Exit" 'or whichever sub name By the way, I'm not one of those people who say GoTos are ALWAYS bad, but it semes to me your first Sub would be simpler in this form: Private Sub TextBox1_Exit(ByVal Cancel _ As MSForms.ReturnBoolean) If TextBox1.TextLength = 9 And _ IsNumeric(TextBox1.Text) Then Exit Sub TextBox1.SetFocus MsgBox " Nebolo zadané správne č*slo! Tu " & _ "možeš zadať len 9 miestne č*slo.", vbCritical, _ " CHYBA ČÍSLA TOVARU" Cancel = True End Sub --- "jogamen" wrote: 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus problem
Hi Bob,
the problem is with code in TextBox2_Enter. If the the code dont find the requested value it should go to line3, msgbox should appear, move focus to the textbox1 and exit/stop sub. "Bob Bridges" wrote: Which sub is running, jogamen? If you're not sure, try putting a MsgBox at the beginning of each Sub: MsgBox "Entering TextBox1_Exit" 'or whichever sub name By the way, I'm not one of those people who say GoTos are ALWAYS bad, but it semes to me your first Sub would be simpler in this form: Private Sub TextBox1_Exit(ByVal Cancel _ As MSForms.ReturnBoolean) If TextBox1.TextLength = 9 And _ IsNumeric(TextBox1.Text) Then Exit Sub TextBox1.SetFocus MsgBox " Nebolo zadané správne č*slo! Tu " & _ "možeš zadať len 9 miestne č*slo.", vbCritical, _ " CHYBA ČÍSLA TOVARU" Cancel = True End Sub --- "jogamen" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Setfocus Problem | Excel Programming | |||
SetFocus problem | Excel Programming | |||
SetFocus problem | Excel Programming | |||
SetFocus Problem | Excel Programming | |||
SetFocus problem | Excel Programming |