Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Focus Problem (Tab order) please help

Status
Not open for further replies.

nomi2000

ISP
Feb 15, 2001
676
0
0
CA
Dera Fellow Programmers
I have three text boxes say Textbox1,Textbox2,Textbox3 Haing Tab Order 0,1,2 respectively
Textbox2 is initially visible false.i have placed the code in Textbox1_LostFocus event
if i=10 then
textbox2.visible=true
textbox2.taborder=1
textbox3.taborder=2
else
textbox2.visible=false
textbox2.taborder=2
textbox3.taborder=2
end if

but the code isn;t working as i want..all i want is that when the condition true then the focus should be at textbox2 and when false its to textbox3
Regards
Nouman

 
Have you tried:

if i=10 then
textbox2.visible=true
textbox2.SetFocus
else
textbox2.visible=false
textbox3.SetFocus
end if

...leaving the TabOrder values as they are initially set?

[glasses]
 
Dear
i can't do this as if i do this as the code is at the LOST_FOCUS so it always fired no matter if u click at that textbox and pressed TAB... strange things happend in VB doesn't it ? :)
Regards
Nouman
 
VB will skip a non visible object in the tab order.

For example. For your three textboxes you have the following tab orders

Text1 0
Text2 0
Text3 0

If all are visible it will go to text1 then text2 then text3

if text2 is invisible it will go to text1 then text3... you do not need to reset the tab orders
 
Dear bjd4c
u say "if text2 is invisible it will go to text1 then text3... you do not need to reset the tab orders" but what would be case if at run-time i make text2 visible i know it should go to text2 but its not going there...i don't know why?
Regards
Nouman
 
please help me out i have 3 text box with tetxbox1,textbox2,texbox3 with textbox2 initialy visble=false and when some condition true then its become visible i have made following code in textbox1 lostfocus event..but it not focus on textbox2 instead go to textbox3..
wondeing why
TEXTBOX1_LOSTFOUCS
if textbox1.text="A" then
textbox2.visible=true
textbox2.taborder=1
textbox3.taborder=2
else
textbox2.visible=false
textbox2.taborder=2
textbox3.taborder=1
Endif
End sub

i don't use textbox2.setfocus as it always setfocus when i lost focus from textbox1..
REgards
Nouman
 
TO Nouman:

173234 (Programmer) is correct. Sometimes a person thinks too much, which is what I'm hearing from you.

You have 3 textboxs (tb1, tb2, tb3). In the design environment you set the properties as follows:

tb1.visible=true : tb1.taborder=0
tb2.visible=false : tb2.taborder=1
tb3.visible=true : tb3.taborder=2

(please note that you abosolutly cannot have all three textboxes to the taboder of zero as was suggested earlier.)

Now, because TB2 is NOT visible, VB will setfocus on the next VISIBLE control (in your case it's TB3 since TB2 is NOT visible).

As you can see, the TabOrder is just incase your user pressed the tab key AND if TB2 was visible it would have the next focus...but since it's NOT then TB3 will have the next focus. So, don't worry about it right now.

To make it jump to TB2, first make it visible then tell vb that TB2 is the location to accept all further input (that's what the SETFOCUS is for).

Again this is from 173234 (Programmer)'s code above:

if i=10 then
textbox2.visible=[red]true[/red]
textbox2.SetFocus
else
textbox2.visible=[red]false[/red]
textbox3.SetFocus
end if

Hopefully you find this clearer. Sorry for any reiterations but sometimes you need to discribe it two different ways to get to the same point. --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
Dear Miggy
i got ur point but u see u missed some point of mine..okay the code u and 172324 works perfect but upto somepoint well u see if u click on tb1 and then click on tb3 and the condition is true then it will went to tb2 because u have forcefull do this but this is not the thing which i wants so i do tab-order thingy...i hope u understand my problem
Regards
Nouman
 
Dear Nomi

Try the Following Code

U have the Textbox Name t1,t2,t3 Resp'ly with tab order 0,1,2 resp'ly

Private Sub T1_Change()
If T1.Text = "A" Then
T2.Visible = True

Else
T2.Visible = False
End If
End Sub

With Regards
Nandagopal.R

 
Nomi, if I understand this situation

You would like the focus to move from textbox1 to textbox3 regarless of the condition if the user clicked on textbox3.

If the user did not click on textbox3, then you want the focus to move to textbox2 if the condition is met, and textbox3 if the condition is not met.

Is this a correct understanding of the flow?


 
"all i want is that [red]when the condition true[/red] then the focus should be at textbox2 and when false its to textbox3"

OK, I think I under stand now...(I think.) So you want TextBox2 to appear if textbox1 loses focus after 10 times <<why??>.

Is it your IF/THEN condition -- which is the ONLY condition I can find in your code -- so I'll presume that that is the &quot;Condition&quot; you keep mentioning.

If this is correct then you will have to create a static variable to count it the number of times that it does lose focus.

To try the following code:

create a blank form;
place 3 textboxes with text2's visible = false;
place 2 command buttons with the text1's caption = &quot;lose focus here&quot;;
paste code from below



Private Sub Command2_Click()
End
End Sub

Private Sub Command1_Click()
Text1.SetFocus
End Sub

Private Sub Text1_LostFocus()
[red]Static[/red] LostFocal As Integer
LostFocal = LostFocal + 1
If LostFocal = 10 Then
Text2.Visible = True
LostFocal = 0
Text2.SetFocus
Else
Text2.Visible = False
End If
Text1.Text = Str$(LostFocal)
End Sub



Run the app click on the first button to make Textbox1 lose focus. Hopefully, this will help you out. If not, then describe in extreme detail exactly what will happen each step of the way for at leaste 3 or 4 times the event is run in sessision. --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
okay let me start from begin :)
i have three textbox tb1,tb2,tb3 with tab-orders 0,1,2 respectively with tb2 initially visible=false
okay now when some condition full-fills at tb1 say tb1.text=&quot;A&quot; then i want to place the focus at tb2 and if it fails then at tb3 with tb2 again visible false..
please if any one of u can do this then open VB project and place three texboxes and place the code in LOST FOCUS of tb1.and tben u will got what i am expeiencing..thanx
TEXTBOX1_LOSTFOUCS
if textbox1.text=&quot;A&quot; then
textbox2.visible=true
textbox2.taborder=1
textbox3.taborder=2
else
textbox2.visible=false
textbox2.taborder=2
textbox3.taborder=1
Endif
End sub


 
Option Explicit

Private Sub Text1_LostFocus()
If Text1.Text = &quot;A&quot; Then
Text2.Visible = True
Text2.SetFocus
Else
Text2.Visible = False

End If
End Sub
 
Ok, you have lost me. I still don't understand why you need to change the TABORDER in RUN mode.

What is the purpose of this program? Why do you want TABORDER changed in RUN mode? What is the purpose of textbox2?

You may be talking about a CHANGE event instead of LOSTFOCUS one. But you didn't write out what was to happen step by step for at least 3 times the TB1's text is changed AND when TB1 loses focus.

My code, as well as everyone else's code, is appropriate for VB. I would suggest that you re-read the posts above incase you may have missed something. I would also suggest that you re-read whatever VB book you may have so that you can get some clearification on VB's processes.

Good Luck-- --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
The following is the only modifications I can give you.
(NOTE: this is written in VB4)

Private Sub Textbox1_LostFocus()
If Textbox1.Text = &quot;A&quot; Then
Textbox2.Visible = True
Textbox2.TabStop = 1
Textbox3.TabStop = 2
Textbox2.SetFocus
Else
Textbox2.Visible = False
Textbox2.TabStop = 2
Textbox3.TabStop = 1
End If
End Sub

Again, good luck. --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top