473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Enter Key Behavior in Text Box

77
Hi,

I have a access form on which there is a tab control with 2 tabs.

each tab has a text box (lets say text1 & text2)

each tab also has a command button (button1 & button2)

What I am looking for is when the user presses the Enter key in a text box, then the button_click event to be called. (true in both the tabs)

I have tried making the buttons to default=true, also tried putting the code in the Exit property of the text box but no luck.

I don't want to change the Enter Key property from the form's design view or from Access Options as the other users who are using the app may not have changed it and would not be able to work.

Pls suggest.

Thanks.
Aug 28 '08 #1
10 31447
yaaara
77
To my surprise, the keypress/keydown event fails to track the Enter key's ascii code as well and does nothing. The code works well for other keys..
Aug 28 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Are you sure the enter keycode is not being recognised, Yaaara? I placed the following in the keydown event of a textbox called Country to check and it worked as expected when the enter key was pressed:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Country_KeyDown(KeyCode As Integer, Shift As Integer)
  2.     If KeyCode = 13 Then
  3.         MsgBox ("Return Pressed")
  4.     End If
  5. End Sub
-Stewart
Aug 28 '08 #3
missinglinq
3,532 Expert 2GB
Stewart's code is pretty standard stuff. Perhaps we need to look at the actual code you've tried.

You can, of course, only assign one command button as the default for a given form. One question does come to mind; does the appropriate event occur when you simply click on one of these command buttons, and what are these buttons supposed to do?

Welcome to Bytes!

Linq ;0)>
Aug 28 '08 #4
yaaara
77
Hi,

Although this code appears to be working (Strangely enough, it was not working yesterday), but I am now getting another issue..

Here is the code that I have:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtEmpIDATT_KeyDown(KeyCode As Integer, Shift As Integer)
  2.     If KeyCode = 13 Then
  3.         If txtEmpIDROD.Text = "" Then
  4.         'do nothing
  5.         Else
  6.             Call cmdHidden3_Click
  7.         End If
  8.     End If
  9. End Sub
  10.  
Whenever I press enter key in the text box, it gives me "error 2185: You can't reference a property or method for a control unless the control has focus"

Pls help...

Thanks.

Stewart's code is pretty standard stuff. Perhaps we need to look at the actual code you've tried.

You can, of course, only assign one command button as the default for a given form. One question does come to mind; does the appropriate event occur when you simply click on one of these command buttons, and what are these buttons supposed to do?

Welcome to Bytes!

Linq ;0)>
Aug 29 '08 #5
NeoPa
32,556 Expert Mod 16PB
There are ways to get around this, but I would strongly recommend against using them.

Instead of that, consider moving your cmdHidden3_Click code out to a separate subroutine and calling THAT from both places.

IE.
Before :
Expand|Select|Wrap|Line Numbers
  1. ...
  2.   Call cmdHidden3_Click
  3. ...
  4. Private Sub cmdHidden3_Click
  5.   Some code
  6. End Sub
After :
Expand|Select|Wrap|Line Numbers
  1. ...
  2.   Call DoSomeCode
  3. ...
  4. Private Sub cmdHidden3_Click
  5.   Call DoSomeCode
  6. End Sub
  7.  
  8. Private Sub DoSomeCode
  9.   Some code
  10. End Sub
Does that make better sense?
Aug 29 '08 #6
yaaara
77
Actually, cmdHidden3_Click is not associated with any control and is just like any other routine.. I did have a command button named cmdHidden3 earlier, but i removed it.. Just didn't change the name of the function (call me lazy for this :-| but I'll change it anyways)

So, in this scenario, the below solution won't work out as it is one and the same thing.. isn't it?

What I am currently doing is using the "Exit" event of the text box for now which works fine with the TAB key, but not with the Enter key... What I want is the trapping of Enter key...

Dunno what to do :-(
Aug 29 '08 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi Yaaara. I think you are overlooking the context of your error message. It appears to relate to textbox txtempIDROD, whose text property is only available when the control has focus. If you set a breakpoint and step through your code you will no doubt find it stops here:

IF txtempIDROD.txt = "" THEN

To resolve this, check for the control being null (not its text property being empty)

IF IsNull(me.txtempIDROD) THEN

The help file entry for the Text property makes all this clear.

Note To set or return a control's Text property, the control must have the focus, or an error occurs. To move the focus to a control, you can use the SetFocus method or GoToControl action.
-Stewart
Aug 29 '08 #8
yaaara
77
I see... Hmmm... didn't check this...

I applied the IsNull function and it works............

Awesome Help Stewart... Many Thanks :-)
Aug 29 '08 #9
missinglinq
3,532 Expert 2GB
Also note that Stewart didn't include the .Value property in his statement, even though the txtempIDROD textbox doesn't have focus. That's because the Default Property of a textbox is .Value and can be omitted.

IsNull(me.txtempIDROD)

and

IsNull(me.txtempIDROD.Value)

mean the same thing in Access VBA.

Linq ;0)>
Aug 29 '08 #10
yaaara
77
Thanks for your inputs as well missing :-)

Also note that Stewart didn't include the .Value property in his statement, even though the txtempIDROD textbox doesn't have focus. That's because the Default Property of a textbox is .Value and can be omitted.

IsNull(me.txtempIDROD)

and

IsNull(me.txtempIDROD.Value)

mean the same thing in Access VBA.

Linq ;0)>
Aug 30 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Serge Myrand | last post by:
Hi, When the cursor is in an INPUT TEXT control and the Enter key is hit, what it's happen. I mean what is the chain of actions starting from that point. I have an ASP application that save...
2
by: ivanhoe | last post by:
All articles and tutorials I've seen on subject of forms say that if there's name and value for submit button(input tag with type="submit"), they'll get submitted along with the rest of the...
7
by: jerrygarciuh | last post by:
Hello, I have been playing with various Googled solutions for capturing the <Enter> key to suppress form submission. My first question is whether anyone has a script that works in all common...
10
by: Deano | last post by:
I think that just about sums it up. Is there a fix/workaround for this?It's quite annoying behaviour and not user-friendly.thanksMartin
7
by: deko | last post by:
I have a textbox in a form into which users enter a string to execute a search. After the user presses Enter, I'd like the focus to go back to the textbox, but the default behavior of the Enter...
0
by: Greg | last post by:
I am working on an application that requires working with numbers in scientific notation. I am using SqlServer as the database and I have created strongly typed data adapters and datasets. The...
5
by: Eric | last post by:
Hi All, I'm very experienced in traditional ASP and am new to (am learning) ASP.NET. FYI: I am initially learning ASP.NET with VB.NET to ease the transition for me. I have encountered what I...
18
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
1
by: kgerritsen | last post by:
I am building an application that will receive input from a barcode scanner. The barcode scanner is configured to append to the front value a single character and hyphen that identify the barcode...
3
by: Jake Barnes | last post by:
I'm researching the Enter key. This is for an Ajax chat application. The designer tells me that she wants people to be able to submit text simply by hitting the Enter key. She wants this to happen...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.