Results 1 to 9 of 9

Thread: [RESOLVED] textbox question?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    269

    Resolved [RESOLVED] textbox question?

    Hi,

    I have 10 textboxes in the form and would like to do something when the user press ENTER, it go to the next textbox (like the tab key does). (Multi-line) text box is not the option.

    THanks!

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: textbox question?

    you can use either textboxName.SetFocus or use the following code
    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = 13 Then
    3.         SendKeys vbTab
    4.     End If
    5. End Sub
    Set FormName.KeyPreview = True in design mode. It will navigate based on the TabIndex value
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: textbox question?

    This is fundamentally what ganeshmoorthy has, but I prefer using the KeyPress event.
    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2. If KeyAscii = 13 Then                ' Enter = Tab
    3.     SendKeys "{tab}"
    4.     KeyAscii = 0
    5. End If
    6. End Sub

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: textbox question?

    Quote Originally Posted by Hack
    This is fundamentally what ganeshmoorthy has, but I prefer using the KeyPress event.
    I agree, but I suggest writting it in the Form_KeyPress instead of Text1_KeyPress. If he uses text1_KeyPress then he has to write it in every textbox, if he does not have control array...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    269

    Re: textbox question?

    Quote Originally Posted by ganeshmoorthy
    you can use either textboxName.SetFocus or use the following code
    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = 13 Then
    3.         SendKeys vbTab
    4.     End If
    5. End Sub
    Set FormName.KeyPreview = True in design mode. It will navigate based on the TabIndex value
    Hi,

    I tried on both form keypress, keydown events, but not working.

    Any reason why?

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: textbox question?

    have you set the KeyPreview of the Form as I mentioned in my earlier post
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: textbox question?

    Again, a matter of preference. If I'm naviagting a specific set of individual controls I prefer coding those individual controls rather than turning "control" over to the form itself.

    In the project I just finished one screen is an Audited Financial Statement log. It has three sections: Statement of Operations, Balance Sheet and Cash Flow. Between those three sections there are 61 textboxs (including two separate comments textboxs) and I coded each of their KeyPress events for the Enter key. It may be a bit more work, but I like the control I have of what textbox does what when.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    269

    Re: textbox question?

    Quote Originally Posted by mapperkids
    Hi,

    I tried on both form keypress, keydown events, but not working.

    Any reason why?

    If KeyAscii = 13 Then ' Enter = Tab
    SendKeys "{tab}"
    KeyAscii = 0
    End If


    Yes, it works on the text1.keypress event, but NOT work on form.keypress event.

    Thanks a lot !

  9. #9
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: [RESOLVED] textbox question?

    ya, you may be right for certain projects, but I prefer coding in the Form which has got more controls, eventhough two controls have to be excluded
    VB Code:
    1. If KeyCode = 13 Then
    2.         If Not (Form1.ActiveControl.Name = "Text1" Or Form1.ActiveControl.Name = "Text2") Then
    3.             SendKeys vbTab
    4.         End If
    5.     End If
    Quote Originally Posted by Mapperkids
    Yes, it works on the text1.keypress event, but NOT work on form.keypress event.
    have you set the Form's KeyPreview property to True...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width