Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Tab backwards

I am trying to tab backwards in some textboxes on a UserForm when Shift
and Tab are pressed. I need to call another sub to validate the value
before I allow the user to exit the current textbox.

It works when the user tabs forwards, I use this code for that...

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 9: KeyAscii = 0: ntl 2
End Select
End Sub

(This calls my validation sub "ntl" and sends the number of the textbox
to it, in this example 2)

To tab backwards I am trying

Private Sub TextBox2_KeyDown(ByVal KeyAscii As MSForms.ReturnInteger,
ByVal Shift As Integer)
If Shift < 1 Then Shift = 0: Exit Sub
If KeyAscii = 9 And Shift = 1 Then ntlbak 2
End Sub

I want this to call my validation sub "ntlbak" and sends the number of
the textbox to it, in this example 2)

But this code does not do it. What am I missing?

Another probably connected problem,

I have noticed a very strange behaviour when I press the ctrl button a
few times, it really messes up the textbox and empties it after
seemingly tabbing the existing value around a little. Can this be
averted?

Garry Jones
Sweden
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Tab backwards

I don't have an answer, just a suggestion.

Personally, I find it much more efficient to do the validation when the user
closes the UserForm. If the controls don't contain valid data, show a MsgBox
and keep the UserForm open. Doing validation when exiting each control
requires all kinds of messy code (as you discovered).

John Walkenbach
For Excel tips, macros, & downloads...
http://j-walk.com/ss


"Garry Jones" wrote in message
...
I am trying to tab backwards in some textboxes on a UserForm when Shift
and Tab are pressed. I need to call another sub to validate the value
before I allow the user to exit the current textbox.

It works when the user tabs forwards, I use this code for that...

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 9: KeyAscii = 0: ntl 2
End Select
End Sub

(This calls my validation sub "ntl" and sends the number of the textbox
to it, in this example 2)

To tab backwards I am trying

Private Sub TextBox2_KeyDown(ByVal KeyAscii As MSForms.ReturnInteger,
ByVal Shift As Integer)
If Shift < 1 Then Shift = 0: Exit Sub
If KeyAscii = 9 And Shift = 1 Then ntlbak 2
End Sub

I want this to call my validation sub "ntlbak" and sends the number of
the textbox to it, in this example 2)

But this code does not do it. What am I missing?

Another probably connected problem,

I have noticed a very strange behaviour when I press the ctrl button a
few times, it really messes up the textbox and empties it after
seemingly tabbing the existing value around a little. Can this be
averted?

Garry Jones
Sweden



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Tab backwards

I am not sure that the following suggestion will work, but it is worth a
try. I have a sheet that I am able to tab forward or backward using te tab
button or the Shift + Tab respectively by protecting the sheet. To protect
the sheet, simply click on the "Tools" menu and then "Protect Sheet". Give
you sheet and password if you prefer. Retype the input and that should do
the trick.
I hope it helps,
Take Care and good luck.
yobeee


"Garry Jones" wrote in message
...
I am trying to tab backwards in some textboxes on a UserForm when Shift
and Tab are pressed. I need to call another sub to validate the value
before I allow the user to exit the current textbox.

It works when the user tabs forwards, I use this code for that...

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 9: KeyAscii = 0: ntl 2
End Select
End Sub

(This calls my validation sub "ntl" and sends the number of the textbox
to it, in this example 2)

To tab backwards I am trying

Private Sub TextBox2_KeyDown(ByVal KeyAscii As MSForms.ReturnInteger,
ByVal Shift As Integer)
If Shift < 1 Then Shift = 0: Exit Sub
If KeyAscii = 9 And Shift = 1 Then ntlbak 2
End Sub

I want this to call my validation sub "ntlbak" and sends the number of
the textbox to it, in this example 2)

But this code does not do it. What am I missing?

Another probably connected problem,

I have noticed a very strange behaviour when I press the ctrl button a
few times, it really messes up the textbox and empties it after
seemingly tabbing the existing value around a little. Can this be
averted?

Garry Jones
Sweden



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Tab backwards

John Walkenbach wrote:

I don't have an answer, just a suggestion.

Personally, I find it much more efficient to do the validation when the user
closes the UserForm. If the controls don't contain valid data, show a MsgBox
and keep the UserForm open. Doing validation when exiting each control
requires all kinds of messy code (as you discovered).


The user has to enter 18 values. But no two values can be alike.

I prefer to check on each input because I can trap the user in that
textbox, highlight the text and issue a msgbox. If I check on userform
close it's going to cause more problems as more than one "double value"
can exist, or even a tripple value.

I have now fixed the code, and can tab backwards and forwards. I used
the "case" solution for both instances keypress and keydown.

But now I have a remaining problem that when the user presses "ctrl and
tab" it enters a tab in the box, I test for "Null" but a blank tab is
not null and the validation I am doing sees a "blank" tab as being okay.
These values are alphanumeric, but I can only find IsNumeric in Excel
VB. How do I test for Alphanumeric? As the initial problem is now fixed
I am also going to repaste this as a new thread.

Garry Jones
Sweden
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
Index backwards LiAD Excel Worksheet Functions 7 September 5th 08 04:42 PM
The A,B,C,D at the top of my page are backwards ambers-life Excel Discussion (Misc queries) 2 February 28th 08 04:13 PM
Help with backwards lookup XFILES Excel Discussion (Misc queries) 1 September 14th 07 05:45 PM
Excel is Backwards! Randy Rich Setting up and Configuration of Excel 9 February 15th 07 05:25 PM
VB backwards compatability to 97 Dave[_34_] Excel Programming 2 December 10th 03 01:51 PM


All times are GMT +1. The time now is 01:28 AM.

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"