PDA

View Full Version : Sleeper: Using tab key on a form



alexanderd
08-25-2005, 01:09 PM
using a the tab key on a userform is great but having tried to jump from say textbox 10 ( if the value =2.5 say ) mis-out textboxes 11-19 and the cursor to be in textbox 20 which has the focus.

if textbox 10 dose not = 2.5 in value textboxes 11-20 are used.

can any one suggest how this can be achieved:banghead:

Norie
08-25-2005, 01:27 PM
I don't understand what you mean 100% but you can set the Tab Order for all the controls on the form by going to View>Tab Order.

mdmackillop
08-25-2005, 01:38 PM
Try

Private Sub TextBox10_AfterUpdate()
If TextBox10 = 2.5 Then TextBox30.SetFocus
End Sub

alexanderd
08-25-2005, 01:44 PM
I don't understand what you mean 100% but you can set the Tab Order for all the controls on the form by going to View>Tab Order.

thank you for a quick response.
i am using tab to move through a series of textboxes. each one has a figure inserted . the value of the 10th textbox is generated by a formula. if the value of the textbox is 2.5 i would like to jump to textbox20.

if the value in textbox 10 is less than 2.5 i would like to use the tab button to progress through the rest of the text boxes.

geekgirlau
08-25-2005, 10:28 PM
The code above will work, but you might have to attach it to a different control. If textbox 10 is a calculated value, for example textbox8/textbox9, then I would add the code to the AfterUpdate event of textbox9.

mdmackillop
08-26-2005, 02:52 AM
Hi GeekGirl,
That doesn't seem to be the case. With the following, after entering the data in textbox2, the cursor goes to textbox6 if the condition is fulfilled.


Private Sub TextBox2_AfterUpdate()
TextBox3 = TextBox1 * TextBox2
End Sub

Private Sub TextBox3_AfterUpdate()
If TextBox3 > 12 Then TextBox6.SetFocus
End Sub


Funnily enough, the following code does not seem to work!


Private Sub TextBox2_AfterUpdate()
TextBox3 = TextBox1 * TextBox2
If TextBox1 * TextBox2 > 12 Then TextBox6.SetFocus
End Sub

alexanderd
08-28-2005, 03:09 AM
Hi GeekGirl,
That doesn't seem to be the case. With the following, after entering the data in textbox2, the cursor goes to textbox6 if the condition is fulfilled.


Private Sub TextBox2_AfterUpdate()
TextBox3 = TextBox1 * TextBox2
End Sub

Private Sub TextBox3_AfterUpdate()
If TextBox3 > 12 Then TextBox6.SetFocus
End Sub


Funnily enough, the following code does not seem to work!


Private Sub TextBox2_AfterUpdate()
TextBox3 = TextBox1 * TextBox2
If TextBox1 * TextBox2 > 12 Then TextBox6.SetFocus
End Sub


sorry one and all but i have been of line for the past couple of days,
i have cut back the form that i want to use to the bare esentials but still just under 100k when zipped i hope it will be accepted.

mdmackillop
08-28-2005, 03:19 AM
Can you confirm the textbox references and criteria for your form "tab jump"?

alexanderd
08-28-2005, 03:45 AM
if the answer to tbxItem3 is vbNo i want to jump to tbxDeposit. this should also work if the answer to tbxItem4,5,6 or 7 is No.
i'm sorry if i've caused any confusion by my initial request for help

TonyJollans
08-28-2005, 04:54 AM
This comes up time and time again in various guises. You have to understand the sequence of events when you move the cursor out of a field.

There are other events as well, but the following occur:

BeforeUpdate on field you're leaving
AfterUpDate on field you're leaving
Exit on Field you're leaving
Entry on Field you're going to (next in tab order in this case)

These events are stacked up ready to roll and processed one at a time. After your code for one event finishes, the next event on the stack will occur, etc., etc.

So, if you do a SetFocus in the AfterUpdate event, say, then the focus is set wherever you want it, and then .....

The rest of the stacked events run - one of these is the Entry to the field that the system thought it was going to (the next in the tab order) - remember that this was stacked up before you did your setfocus. When this Entry event runs (whether or not you have any code for it) it moves the focus - overriding what you did earlier.

Some events (for example, BeforeUpdate) have a Cancel parameter and if you set this to True, it will clear the stacked events. You cannot clear the stack any other way. (in case you know Access, it is slightly different in Access Forms where you can 'cheat')

In your case, you don't want to cancel so you have to get in and set the focus where you want it after the system has done its stuff - that is in the Entry event of the next field (or later).

I have to guess a bit, but I think you want to put your checking of Textbox10 in the Entry event for Textbox11.

mdmackillop
08-28-2005, 05:00 AM
Further to Tony's comments,
vbNo is not being returned as a text value to your textbox. Your code will need to be something like


iReply = MsgBox("mandatory amount field. " & " 'ENTER.", vbYesNo)
If iReply = vbNo Then
tbxDeposit.SetFocus
End If

alexanderd
08-28-2005, 07:19 AM
This comes up time and time again in various guises. You have to understand the sequence of events when you move the cursor out of a field.

There are other events as well, but the following occur:

BeforeUpdate on field you're leaving
AfterUpDate on field you're leaving
Exit on Field you're leaving
Entry on Field you're going to (next in tab order in this case)

These events are stacked up ready to roll and processed one at a time. After your code for one event finishes, the next event on the stack will occur, etc., etc.

So, if you do a SetFocus in the AfterUpdate event, say, then the focus is set wherever you want it, and then .....

The rest of the stacked events run - one of these is the Entry to the field that the system thought it was going to (the next in the tab order) - remember that this was stacked up before you did your setfocus. When this Entry event runs (whether or not you have any code for it) it moves the focus - overriding what you did earlier.

Some events (for example, BeforeUpdate) have a Cancel parameter and if you set this to True, it will clear the stacked events. You cannot clear the stack any other way. (in case you know Access, it is slightly different in Access Forms where you can 'cheat')

In your case, you don't want to cancel so you have to get in and set the focus where you want it after the system has done its stuff - that is in the Entry event of the next field (or later).

I have to guess a bit, but I think you want to put your checking of Textbox10 in the Entry event for Textbox11.

setting the focus dose not seem to be a problem only the movement of the cursor from the field i exit to the field i have set the focus to.
the tab button will go to the next in tab but not the textbox i have set the focus to.
any suggestions or examples you can direct me to i would appreciate

TonyJollans
08-28-2005, 08:15 AM
Sorry, terminology problem I think, but now that I've had a look at your file I don't think the setfocus is the issue at all.

Look at Malcolm's last post.

You display a msgbox and then you check the textbox for a string value ("vbNo") - it's not going to be true. Instead of ..


If tbxitem3 = "vbNo" Then

try ..


If iReply = vbNo Then

alexanderd
08-28-2005, 11:19 AM
Sorry, terminology problem I think, but now that I've had a look at your file I don't think the setfocus is the issue at all.

Look at Malcolm's last post.

You display a msgbox and then you check the textbox for a string value ("vbNo") - it's not going to be true. Instead of ..


If tbxitem3 = "vbNo" Then

try ..


If iReply = vbNo Then

i thank you and all who have contributed to this discusion but at present:banghead:
i have tried that
If iReply = vbNo Then
tbxDeposit.SetFocus
yes the focus is set ok but i still have to tab all the way

TonyJollans
08-28-2005, 09:28 PM
It seems to work for me, but ..

What do you mean >> the focus is set ok but i still have to tab all the way

By definition, the focus is on the field the cursor is in.

You said in an earlier post >> if the answer to tbxItem3 is vbNo i want to jump to tbxDeposit.

But the code tries to set the focus on tbxGrandTot.

alexanderd
08-30-2005, 12:43 PM
It seems to work for me, but ..

What do you mean >> the focus is set ok but i still have to tab all the way

By definition, the focus is on the field the cursor is in.

You said in an earlier post >> if the answer to tbxItem3 is vbNo i want to jump to tbxDeposit.

But the code tries to set the focus on tbxGrandTot.

if i say no the focus "seems" to be set to tbxGrandtotal i say seems because it overides the same question at tbxItem4 , 5 , 6, & 7 and allows you to tab through without stopping. i would like to see the cursor flashing on tbxGrandtotal which will then have the focus.
useing the tab key then would update the total on exit

TonyJollans
08-30-2005, 01:55 PM
I'm sorry but I don't understand what you want.

I suspect your problem is your logic - the code (subject to the vbNo correction) appears to 'work'; if it isn't doing what you want, it's because you are checking the wrong conditions.

Your entry code for TextBox3, under certain circumstances, sets focus to the GrandTotal - and disallows input in TextBox3.

Your Entry code for TextBox4 checks TextBox3 - but if you've disallowed input in TextBox3 then that check fails.

alexanderd
08-30-2005, 02:12 PM
I'm sorry but I don't understand what you want.

I suspect your problem is your logic - the code (subject to the vbNo correction) appears to 'work'; if it isn't doing what you want, it's because you are checking the wrong conditions.

Your entry code for TextBox3, under certain circumstances, sets focus to the GrandTotal - and disallows input in TextBox3.

Your Entry code for TextBox4 checks TextBox3 - but if you've disallowed input in TextBox3 then that check fails.
i will start again and check on what i have done an see where my logic fails when sorted i will be back