|
-
Oct 27th, 2001, 04:58 AM
#1
KeyAscii
hi there,
I use this code on each text_KeyPress
i think it could be use only at once in the form
instead of rewrite this code every time ,
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
text2.SetFocus
End If
End Sub
could someone help pls.
thanks in advance
-
Oct 27th, 2001, 05:45 AM
#2
PowerPoster
Put your text boxes into a control array. So the code would be:
Private Sub Text_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
Text(Index + 1).SetFocus
End If
End Sub
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 27th, 2001, 06:25 AM
#3
Try setting the Form's KeyPreview to True, and put your code in the Forms KeyPress event.
-
Oct 28th, 2001, 01:32 AM
#4
thanks for the reply
I have try both
1:-
I have create 3 textbox
properties
text1.index=1
text2.index=2
text3.index=3
setting the Form's KeyPreview to True
and then I have copied
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text(Index + 1).SetFocus
End If
End Sub
but it's still not working
2:-
you'v said Put your text boxes into a control array
actually I don't know what is a control array
pls. I need more explanation.
thanks again for you help.
-
Oct 28th, 2001, 01:37 AM
#5
Member
should be
text1 = index 0
text1 = index 1
text1 = index 2
-
Oct 28th, 2001, 01:40 AM
#6
Member
you could try....
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Call IfKeyIsPressed
End Sub
Public Sub IfKeyIsPressed(KeyAscii As Integer)
If KeyAscii = 13 Then
text2.SetFocus
End If
End Sub
-
Oct 28th, 2001, 01:50 AM
#7
PowerPoster
hi
if u dont want to worry about control arrays and keypress events etc u can use this 'trick'. This works as long as u dont already have a Default command button on ur form.
Add a command button. Set properties as follows
Default - True
TabStop - False
Name - cb_tab
Then make it very small and move it behind a textbox or something. Use send to back from the right click menu.
Put this code in the button event and that is all u need. NB. u can also check for different types of controls see eg 2
VB Code:
'EXAMPLE 1. SIMPLE KEYPRESS
Private Sub cb_tab_Click()
On Error Resume Next
SendKeys "{tab}"
End Sub
VB Code:
'EXAMPLE 2. CHECK FOR TYPE OF CONTROL
Private Sub cb_beepstop_Click()
On Error Resume Next
If TypeOf fctlFocusControl Is ComboBox Then
'Yadda yadda yadda
Else
SendKeys "{tab}"
End If
End Sub
'Then in every controls got focus event set the fctlfocuscontrol variable to the current control
ie Set FctlFocusControl = Text1 ' etc etc
Regards
Stuart
-
Oct 28th, 2001, 01:52 AM
#8
PowerPoster
PS
NB The text boxes should have sequential tab order numbers
eg Text1 : TabIndex =0
Text2 : TabIndex =1
etc
Regards
Stuart
-
Oct 28th, 2001, 04:52 AM
#9
thank you Stuart & Sensimillia for the reply
i have tried your example & code
works perfects
but i still want to ask Sensimillia about the code sent , i realy want to learn something becuase some time i use 256 tool as in my product , want to save cmd button so,i tried this
properties:-
text1 = index 0
text1 = index 1
text1 = index 2
and i have copied your code as:-
Private Sub Text1_KeyPress(KeyAscii As Integer)
Call IfKeyIsPressed
End Sub
Public Sub IfKeyIsPressed(KeyAscii As Integer)
If KeyAscii = 13 Then
'text2.SetFocus ' i tried it but not working properly
text(index+1).setfocus ' i tried it also but not working
either
End If
End Sub
sill not got it ,
so , is there any thing i have missed pls. advice & sorry for the disturb
thank you again for the help
-
Oct 28th, 2001, 05:20 AM
#10
PowerPoster
Hi again
I can help u with Sensimillia's code also
There are a number of ways using S's code also
On your form create a textbox called Text1. Copy it using Ctrl-C and paste it Ctrl-V... when it asks u if u want to create a control array press Yes. U now have Text1(Index = 0) and Text1(Index = 1). Paste a few more times to get more boxes.
You can now tab between textboxes using a number of methods... here are 2
VB Code:
'1) If textboxes are in tabindex order
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
'Note that the sub now has an Index As integer item. This
'is the index number of each box u created so u can know
'which one the user is in.
If KeyAscii = 13 Then 'Check for the enter key (13)
KeyAscii = 0 'Reset it to stop beeping
SendKeys "{tab}" 'Tab to next control
End If
End Sub
VB Code:
'2) Tabbing between controls based on index numbers
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then'Check for enter key
KeyAscii = 0 'Reset for beeping
If Index < Text1.UBound Then 'If not last textbox
Text1(Index + 1).SetFocus 'send focus to next item
Else 'if last control send focus back to first item
Text1(Text1.LBound).SetFocus
End If
End If
End Sub
-
Oct 29th, 2001, 12:50 AM
#11
thank you for all the reply,
I really appreciated
it work fantastic + I have know what is the control array also
I LOVE VB Q&A because of you
thank you again
-
Oct 29th, 2001, 02:04 AM
#12
Hyperactive Member
im glad you got it workign
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|