UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> How to use Enter key as an event after entering value in a text box    
 
   
HuntsvilleMan
post Dec 11 2009, 09:49 AM
Post #1

UtterAccess Addict
Posts: 211
From: Huntsville, Alabama



How can pressing the Enter key in a "text box" on a form make a subprogram run? I see a key press events but then the event happens while I'm typing values in the text box.

Thanks for suggestions.

Mike
Go to the top of the page
 
+
GroverParkGeorge
post Dec 11 2009, 10:06 AM
Post #2

UA Admin
Posts: 19,212
From: Newcastle, WA



A little more clarity please.

You have text box control on a form. You want to trigger a "subprogram" when your user presses the Enter key while the cursor is in that control? But you ALSO want your user to be able to continue typing values WHILE that "subprogram" runs?

First, by "subprogram" do you mean a Sub procedure in that form? e.g.

Private Sub YourSub()
------ code to do things
End Sub

What would that Sub actually do? Why do you want to run it simultaneously with continued data entry?

If my understanding of this situation is accurate, you are going to have to let this sub run, after you trigger it, before you can continue typing in the control. But first, we need to be clear on what the workflow should be.

Thanks.

George
Go to the top of the page
 
+
fkegley
post Dec 11 2009, 10:14 AM
Post #3

UtterAccess VIP
Posts: 23,583
From: Mississippi



For me, it has always worked out better to use the double-click event of a text box to run a subprogram, such as opening a date control. The double-click is more likely to be a deliberate action than a single-click or pressing a particular key.

If though you want to use the Enter key, then you need code in the KeyPress event that discriminates between the key codes. Something like:

If KeyAscii = vbKeyReturn Then
Me.Text2.SetFocus
End If
Go to the top of the page
 
+
fkegley
post Dec 11 2009, 10:17 AM
Post #4

UtterAccess VIP
Posts: 23,583
From: Mississippi



George, I think he has discovered the KeyPress event and put the command in there all right, except there is no discrimination among the key codes. Any key sets off the event code.
Go to the top of the page
 
+
HuntsvilleMan
post Dec 11 2009, 10:24 AM
Post #5

UtterAccess Addict
Posts: 211
From: Huntsville, Alabama



Thanks for the suggestions. The application displays a person's information when an identification number is entered. The form has only one data entry item ( an integer). Based on the value entered, the screen populates with appropriate information. Since the user only enters one number with no need to navigate about the screen, a key press of the Enter key seemed to be the easiest data entry scheme.

Thanks for the suggestions

Mike
Go to the top of the page
 
+
HuntsvilleMan
post Dec 11 2009, 10:41 AM
Post #6

UtterAccess Addict
Posts: 211
From: Huntsville, Alabama



I put the following code in the key down event of the text box in hopes it would only respond to the Enter key.

If vbKeyReturn = 13 Then
MyProgram
End If

I'm still not sure why this doesn't work. It seems that every key press makes MyProgram run.

Thanks

Mike
Go to the top of the page
 
+
fkegley
post Dec 11 2009, 11:13 AM
Post #7

UtterAccess VIP
Posts: 23,583
From: Mississippi



Realize that vbKeyReturn is part of a enumeration, a way to use a friendlier value to represent a not-so-friendly value, such as the ASCII code of a key press. vbKeyReturn has a value of 13, so your code is actually this:

If 13 = 13 Then
MyProgram
End If

Therefore it doesn't work because you are equating vbKeyReturn to ITSELF. What I think you need it this instead:

If KeyCode = vbKeyReturn Then
MyProgram
End If
Go to the top of the page
 
+
HuntsvilleMan
post Dec 11 2009, 11:29 AM
Post #8

UtterAccess Addict
Posts: 211
From: Huntsville, Alabama



Never underestimate the ability of a novice to mess up good advice. When I took another look at the suggestion, I noticed that the key down event receives an integer named "keycode" as a parameter so I tried your suggestion as:

If KeyCode = vbKeyReturn Then
MyProgram
End If


Now when I hit the Enter key after typing the integer value it fires off "MyProgram" to poulate the screen with the appropriate values.

Thanks for the tip. Now, where can I find some tutorial stuff to read that will take me from "novice" Access user to say "intemediate level?" I'm especially puzzled over where all of these values (like vbKeyReturn) are listed.

My next step is to add a bit of color where fields on the screen have missing values. Any advice on setting a text box to a different color. Are there values like vbKeyReturn for setting simple color values?

Thanks

Mike
Go to the top of the page
 
+
jleach
post Dec 11 2009, 12:02 PM
Post #9

UtterAccess Editor
Posts: 6,709
From: Capital District, NY, USA



QUOTE
where can I find some tutorial stuff to read that will take me from "novice" Access user to say "intemediate level?"


Right here's a great place to start. the microsoft.public.access newsgroups are good as well, that's where I learned the majority of things I know.

QUOTE
I'm especially puzzled over where all of these values (like vbKeyReturn


There's hundreds of thousands of these... you can (from the VB Window) go under View and take a look at the Object Browser, but there's so much information there it's hard to understand it unless you understand it... (IMG:http://www.utteraccess.com/forum/style_emoticons/default/crazy.gif) One thing that helps me a lot is putting the cursor inside the word (ex. somewhere in vbKeyReturn) and pressing F1 to bring up the VBA help... the help generally has a list of a large majority of these types of enumerations as well as related information. When used correctly, the Help is a massive resource for information.

QUOTE
My next step is to add a bit of color where fields on the screen have missing values. Any advice on setting a text box to a different color. Are there values like vbKeyReturn for setting simple color values?


Me.TextBoxName.Backcolor = vbRed

... highlight vbRed and hit F1 and you should see a list of related enumerations for vb Color constants.

Once you start to get more familiar with how vb names these things, googling them works fairly well also. For instance... "VBA color constants" should return a few links that would give lists on this stuff. The ironic part is that often you don't know what to look for until you find it.

hth
Go to the top of the page
 
+
fkegley
post Dec 11 2009, 01:06 PM
Post #10

UtterAccess VIP
Posts: 23,583
From: Mississippi



You're welcome. I am glad I could help.

As far as your new question goes, I think you can do that with conditional formatting. I believe it is on the Format menu.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th May 2013 - 07:09 PM