Solved

TextBox, How does it work?

Posted on 2004-04-01
10
189 Views
Last Modified: 2013-12-25
if i enter data into a textbox and DO NOT tab/cr the data cannot be passed, why? what is the work around ? e.g. type data into the textbox and then hit a button that execute programmed action without the need to activate the box with a tab or cr. thanx
0
Comment
Question by:vbsterxx
10 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 10739017
Hitting enter on your text box can perform the action


Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = 13 Then
    'do your code here
    MsgBox "Do SomeThing Here"
  End If
End Sub
0
 
LVL 5

Expert Comment

by:Alok-Agarwal
ID: 10739081
hi,

Sorry but can you please provide more clarifications on the requirement so that I can help you out.

Thanks
Alok
0
 
LVL 6

Expert Comment

by:mmusante
ID: 10739411
>... data cannot be passed, why?
I don't konw where you are trying to pass data ... but why dont you pass your data in the 'Change' event?

Please can you explain a little more?
0
 
LVL 39

Expert Comment

by:appari
ID: 10740153


do you mean enter text in text box and press enter it should run code in a command click event? if so just set the default property of the command button to true.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 10740882
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        KeyAscii = 0 ' Suppresses the Beep
        Command1_Click
    End If
End Sub

Private Sub Command1_Click()
    Debug.Print Text1.Text
End Sub
0
 
LVL 2

Expert Comment

by:jasonholland
ID: 10741907
Ok, its simple. Take the code below and cut and paste into a form named Form1 with a text box named Text1. That is all you need.
Then run the program, type whatever you want into the text box, then press Ctrl + c to get a message box of the contents of Text1.


Cut and Paste the code below into a form


Private Sub Form_Load()
    ' In order to select your keys you want to trap for, take a look at the Object Browser
    ' by pressing F2 in VB and then looking up these two constant sets
   
    ' "ShiftConstants"  (Used for Shift, Alt, and Ctrl)
    ' "KeyCodeConstants"   (Used for the Ascii characters A-Z, a-z, 0-9, etc. It will also show shift, alt, and ctrl. However
    ' if you press Ctrl + c the KeyCode will hold the value of 'c' and the ShiftConstant will hold the ShiftConstant for Ctrl.
    ' There is 1 tricky bit here. In the KeyCodeConstants Ctrl is vbKeyControl, Shift is vbKeyShift, BUT Alt IS NOT vbKeyAlt!
    '  It is vbKeyMenu.

    ' Do not use the KeyPress event, as it will only pass Ascii characters, A-Z and a-z and 0-9 etc...
    ' You wont get the value for shift, or ctrl, or alt etc...
   
    ' Use the Text1_KeyDown event, this way you can trap for the Alt, Ctrl, and Shift keys
    ' They keycode will be the constant value in the "KeyCodeConstants", and the shift will be the ShiftConstant
    ' If you wanted to trap someone pressing Ctrl + c and send the text somewhere look at the subroutine below
   
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

    ' Uncomment the lines below if you want to see what keys you are pressing
    'Debug.Print "KeyDown"
    'Debug.Print KeyCode
    'Debug.Print Shift

    If KeyCode = vbKeyC And Shift = vbCtrlMask Then
        MsgBox Form1.Text1.Text
    End If

End Sub




Good Luck,
I hope this is what you were looking for.
Jason Holland
0
 
LVL 2

Expert Comment

by:jasonholland
ID: 11043559
I am interested. If there is more that I need to do please let me know.
Jason Holland
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 11113177
PAQed - no points refunded (of 200)

Computer101
E-E Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 78
Microsoft Access combo box help 2 38
how to know if my Checkbox is True in VB6.0? 9 40
Help me. 3 46
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now