Login | |
|
 |
Code to make Enter key act like Tab - 6/16/2006 12:58:30 AM
|
|
 |
|
| |
zeg37
Posts: 15
Score: 0
Joined: 6/16/2006
Status: offline
|
I am working with a data access page and I have an unbound text field that is used to search for specific records from my database. I would like to limit the amount of text a user can type into the field, or better yet write code to cause the enter key to respond like a tab key. I've found a variety of java code and some visual basic code for changing the enter key, but haven't had any success getting it to run. I would prefer to use VBScipt if possible. I've tried many variations of the code below without success: <Script language=vbscript event=onkeypress for=vProject> <!-- Sub vProject_KeyPress (KeyAscii as Integer) If KeyAscii = 13 then KeyAscii = 0 Sendkeys "{TAB}" End If End Sub --> </SCRIPT> Any suggestions would be greatly appreciated. Zeg
|
|
| |
|
|
|
 |
RE: Code to make Enter key act like Tab - 6/16/2006 2:23:20 AM
|
|
 |
|
| |
mikeock
Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
|
The first issue that i see with your code, is that appers you are trying to attempt VB syntax in VBS. the reason I say this is becuse you have KeyAscii as Integer). VBS does not allow you to declare the type of variable they are all seen as variant type. So instead make the line Sub vProject_KeyPress (KeyAscii) . The other thing that I would look at, is the onkeypress event. I can't quite recall how to use this but I do believe the syntax you have is incorrect. May8be check out Microsft's Script center page and look at the HTA section. Hope this Helps! Mike
_____________________________
My sig sucks!
|
|
| |
|
|
|
 |
RE: Code to make Enter key act like Tab - 6/16/2006 3:00:23 AM
|
|
 |
|
| |
mikeock
Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
|
Zeg, also to do a sendkeys method you need to create the object to do the sendkeys. Something along these lines: Set WshShell = Wscript.CreateObject("Wscript.Shell") then to do your sendkeys you do a WshShell.Sendkeys "{TAB}" so it would look more like this Sub vProject_KeyPress (KeyAscii) Set WshShell = Wscript.CreateObject("Wscript.Shell") If KeyAscii = 13 then KeyAscii = 0 WshShell.Sendkeys "{TAB}" End IF Set WshShell = nothing End sub
_____________________________
My sig sucks!
|
|
| |
|
|
|
 |
RE: Code to make Enter key act like Tab - 6/16/2006 7:28:36 AM
|
|
 |
|
| |
mikeock
Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
|
The two books that I use for vbscript are VBScript programmers reference (Wrox bout $34.95) and VBS in a nutshell (o'rielly bout $24.95). The wrox book has a lot of examples and breakdowns. I use the nutshell book more a s a quick reference for a function. Back to the issue. I don't think that the line KeyAscii = 0 is required... Try it without it and see what happens! Let me know if you need further assistance!
_____________________________
My sig sucks!
|
|
| |
|
|
|
 |
RE: Code to make Enter key act like Tab - 6/16/2006 7:49:45 AM
|
|
 |
|
| |
ebgreen
Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
|
If this is being done in a web page, then here is how I handle this situation (I hate sendkeys). First I make sure that the tabindex property is set for all the controls that I want to be ablr to tab through and that the indices are in the proper order. Next in the OnKeypress event sub for each control I put this: Sub vProject_OnKeyPress(oKey) If oKey.KeyCode = 13 Then GotoNextTab(window.event.srcElement.TabIndex) End If End Sub Then I have this sub somewhere in my code: Sub GotoNextTab(nTab) Dim oNode For Each oNode In document.all If oNode.TabIndex = nTab + 1 Then oNode.Focus End If Next End Sub
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Code to make Enter key act like Tab - 6/19/2006 2:02:38 AM
|
|
 |
|
| |
mikeock
Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
|
<!-- --> is an html comment tag. Dunno if it shoudl work within the script tag or not
_____________________________
My sig sucks!
|
|
| |
|
|
|
|
|