Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 257
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setfocus Problem Craig M Excel Programming 9 March 3rd 07 08:29 PM
SetFocus problem cesw Excel Programming 1 September 10th 05 08:19 PM
SetFocus problem JH Excel Programming 1 April 18th 05 03:55 PM
SetFocus Problem Todd Huttenstine[_2_] Excel Programming 2 January 19th 04 10:50 PM
SetFocus problem RFraley Excel Programming 2 September 7th 03 01:18 PM


All times are GMT +1. The time now is 07:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"