473,465 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

text box event in a DAP

76 New Member
This is done in an Access 2003 ADO data access page.

I've got a text box (txtSearch) and I've got a command button (cmdSearch).

The cmdSearch has this onclick event:
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=vbscript event=onclick for=cmdSearch>
  2. <!--
  3. Dim rs
  4. Set rs = MSODSC.DataPages(0).Recordset.Clone
  5. On error resume next
  6.  
  7. rs.find "[WO NUMBER]=" & (txtSearch.value)
  8.  
  9. If (err.number <> 0) Then
  10.     Msgbox "Error: " & err.number & " " & err.description,,"Invalid Search"
  11.     Exit Sub
  12. End If
  13. cmdWOSearch.focus
  14.  
  15. If (rs.bof) or (rs.eof) Then
  16.     Msgbox "Error Work Order not found.",,"Search Done"
  17.     Exit Sub
  18. End If
  19. MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark
  20. cmdWOSearch.focus
  21. -->
  22. </SCRIPT>
When a user enters text into txtSearch and hits enter I would like to call the cmdSearch onclick event. As of now, all the enter key does inside the txtSearch box is create a new line.
Really this is three questions.
How to catch the enter key when it is pressed in the txtSearch box.
How to call an event from another event.
Are data access pages good to use?
Oct 15 '07 #1
5 2624
kcddoorman
76 New Member
So I figured out question number two on my own. You can interact with other elements in the page like so. cmdSearch.focus or cmdSearch.click or cmdSearch.dblclick, pretty cool.

I'm not sure why this won't work. It may have something to do with ascii code in VBscript?
So I try this.
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=vbscript event=onkeypress for=txtSearch>
  2. <!--
  3. dim KeyAscii
  4. KeyAscii = Asc(UCase(Chr(KeyAscii)))
  5. If KeyAscii = VbKeyEnter then
  6. cmdSearch.click
  7. End if
  8. -->
  9. </SCRIPT>
So for every key I press while txtSearch has focus this event will run. The problem is that this will catch everything. It won't weed out the return/newline/013/enter key that is pressed.
I thought maybe the page didn't like the VbKeyEnter criteria so I tried this
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=vbscript event=onkeypress for=txtSearch>
  2. <!--
  3. dim KeyAscii
  4. KeyAscii = Asc(UCase(Chr(KeyAscii)))
  5. If KeyAscii = Asc(013) then ' I also tried chr(13) and chr(13) & chr(10)
  6. cmdSearch.click
  7. End if
  8. -->
  9. </SCRIPT>
This doesn't catch anything at all. The only thing I'm catching is a cold. Curse you fall season.

I'm not clear on how the event: onkeypress works I guess. I declare KeyAscii and use it to test for the chr(13) but how does the keypressed by the user get to be equal to KeyAscii? onkeypress is simply an event does it pass anything to the code? From what I'm reading about this Access may be eating my enter keypress.
Oct 15 '07 #2
kcddoorman
76 New Member
It has to be eating it. This code should work.
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=vbscript event=onchange for=txtSearch>
  2. <!--
  3. dim searchstr
  4. searchstr = txtSearch.onkeypress
  5. Dim enter
  6. enter = chr(13)
  7. If searchstr = enter then
  8. msgbox (enter) & "there it is",,"OK"
  9. cmdSearch.click
  10. Exit Sub
  11. End If
  12. -->
  13. </SCRIPT>
I've read up about this problem in forms when the command button's property .default is set to true. How can I change this in a vbscript with MSODSC.

Thanks and I appreciate any light you may shed,
James
Oct 15 '07 #3
ADezii
8,834 Recognized Expert Expert
This is done in an Access 2003 ADO data access page.

I've got a text box (txtSearch) and I've got a command button (cmdSearch).

The cmdSearch has this onclick event:
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=vbscript event=onclick for=cmdSearch>
  2. <!--
  3. Dim rs
  4. Set rs = MSODSC.DataPages(0).Recordset.Clone
  5. On error resume next
  6.  
  7. rs.find "[WO NUMBER]=" & (txtSearch.value)
  8.  
  9. If (err.number <> 0) Then
  10.     Msgbox "Error: " & err.number & " " & err.description,,"Invalid Search"
  11.     Exit Sub
  12. End If
  13. cmdWOSearch.focus
  14.  
  15. If (rs.bof) or (rs.eof) Then
  16.     Msgbox "Error Work Order not found.",,"Search Done"
  17.     Exit Sub
  18. End If
  19. MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark
  20. cmdWOSearch.focus
  21. -->
  22. </SCRIPT>
When a user enters text into txtSearch and hits enter I would like to call the cmdSearch onclick event. As of now, all the enter key does inside the txtSearch box is create a new line.
Really this is three questions.
How to catch the enter key when it is pressed in the txtSearch box.
How to call an event from another event.
Are data access pages good to use?
  1. The ENTER Key is probably not being recognized in the KeyPress() Event because you have the Move after enter Option set to Next Field (Tools ==> Options ==> Move after enter ==> Next Field).
  2. All is not lost since you can trap the ENTER Key in the KeyDown() Event of [txtSearch], via the return value in the KeyCode Argument, then execute the Click() Event of cmdSearch as such:

    Expand|Select|Wrap|Line Numbers
    1. Private Sub txtSearch_KeyDown(KeyCode As Integer, Shift As Integer)
    2.   Const conEnterKey = 13
    3.  
    4.   If KeyCode = conEnterKey Then
    5.     Call cmdSearch_Click
    6.   End If
    7. End Sub
Oct 16 '07 #4
kcddoorman
76 New Member
That would work great if it were in a form but this is a data access page.
Microsoft Says:
"VBScript is designed to be a small and lightweight interpreted language. It is also designed to be safe, so it does not include direct access to the underlying operating system. VBScript syntax and usage is similar to VBA, except that the following features and keywords are omitted:

Language elements such as: #Const, #If...Then...Else, CVar, CVDate, Date, Declare (for declaring DLLs), Debug.Print, DoEvents, End, Erl, Error, GoSub...Return, GoTo, Like, LinkExecute, LinkPoke, LinkRequest, LinkSend, LSet, Mid, On Error GoTo, On...GoSub, On...GoTo, Optional, Option Base, Option Compare, Option Private Module, ParamArray, Resume, Resume Next, RSet, Static, Stop, Str, StrConv, Time, Type...End Type, TypeOf, and Val"

I wonder if I could create a function that effects the page globally. The default event for pressing the enter key while a textbox has focus is to create a new line. This is being caught by something else. I just need to turn "it" off. What ever "it" is. It is so easy to do in a form with the on enter event, but alas there is no such animal in the DAP world of VBScript.
Oct 16 '07 #5
kcddoorman
76 New Member
Here is how you do it.
1. Open the Microsoft Script Editor
2. Select your textbox from the objects drop down list.
3. Select the onkeypress event from the events drop down list.
4. Insert this code between the <script>...</script>
Expand|Select|Wrap|Line Numbers
  1. if window.event.keyCode = 13 then
  2. YOURBUTTONHERE.click()
  3. end if
  4.  
13 is the ascii number for the enter button you can use any button you want here.
So simple.

I also found another line of code that throws away the enter button so people are not entering the wrong(return carriage) data into the database.
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT>
  2.  
  3. function kH(e) {
  4. var pK = document.all? window.event.keyCode:e.which;
  5. return pK != 13;
  6. }
  7. document.onkeypress = kH;
  8. if (document.layers) document.captureEvents(Event.KEYPRESS);
  9.  
  10. </SCRIPT>
I appreciate your input on this topic. I hope I'm not getting a bad rap on here. I seem to post to my own questions more than anything. I should just keep a journal or something, but this way I get to share information for anyone who actually searches for their problem before asking the question.
Thanks for being my idea-bouncing-off-wall. thescripts FTW!
Oct 16 '07 #6

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

Similar topics

2
by: Tonino | last post by:
Hi, I have a small Tkinter app that gets data from a socket connection to a "server". The app has a Text() widget to display the info that it gets from the socket connection. I have the...
1
by: Mike | last post by:
I have a combo box and a text box. Text to be display will be contigent upon what is selected via the combo box. How do I do this? I put the following code in the text box object: var a =...
2
by: charlie_M | last post by:
I have the following code: <script type=text/javascript> function hide_tooltip(){ var hp = document.getElementById("tooltipper"); hp.style.left=0; hp.style.top=0; hp.style.width=1;...
1
by: David Smith | last post by:
What I want to be able to do: A textbox is available that the user can enter information into. Specifically (for the purposes of this post), the user is asked to enter a number, and that number...
10
by: mg | last post by:
I want to enter characters in a TextBox in a WebForm, press a Button in the WebForm, and read the characters that were typed into the TextBox from within the Button_Click event handler. The main...
3
by: excel_hari | last post by:
Hi, I couldnt locate a Classic ASP group hence posting here. One of my colleagues has designed an intranet site and one of the pages has a drop-down box with close to 300 options. I want to...
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
0
by: Steven Bethard | last post by:
I'm trying to align an XML file with the original text file from which it was created. Unfortunately, the XML version of the file has added and removed some of the whitespace. For example:: ......
8
by: nma | last post by:
Hi Again How do I put a text color in case option? Eg I want the case:ALL the text will be red, case Dialogue the text is yellow, case Montage the text is blue and so on. What is the best way to...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.