Solved

ON Enter

Posted on 2011-02-23
5
273 Views
Last Modified: 2012-05-11
Experts,

I have a search form
After I enter in the criteria I see a list of records.
I want to be able to tab down to the first record, hit enter and then the code will fire to open up the other form.  
I thought I could use the event "On Enter" but it seems to fire "On Open" of teh form.  
When I open the form, the form immediately fires the On Enter macro and I did not even hit enter.  

I also tried ON Focus but same thing. I have to shutdown db in order to stop the code as it seems to loop indefinitely.  

What other method can I use?  Right now, I use the On click event of the field I am clicking to fire the open form code but it takes time to grab the mouse and then click that particular field.  It would be quicker to hit tab and then press enter.

the setup is main form then subform. The sub is where I am setting the On Enter.  On the main form I have setfocus to the search box.  

thank you.  
0
Comment
Question by:pdvsa
  • 3
5 Comments
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34961853
On Enter is rarely useful.  If the list is a datasheet, you can use the DblClick event.  If it is a listbox, use AfterUpdate if is a single-select listbox, or work with the ItemsSelected collection if is a multi-select listbox.  The event in question is on the search subform (or listbox), not the form it opens.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34961866
Here is some code for working with the ItemsSelected collection:
Private Sub cmdExportData_Click()

On Error GoTo ErrorHandler

   Dim intColumn As Integer
   Dim intColumns As Integer
   Dim intCount As Integer
   Dim intIndex As Integer
   Dim intRow As Integer
   Dim intRows As Integer
   Dim lst As Access.ListBox
   Dim strData As String
   Dim strPrompt As String
   Dim strTest As String
   Dim strTitle As String
   Dim varItem As Variant
   
   Set lst = Me![lstSelectContacts]
      
   'Check that at least one item has been selected
   If lst.ItemsSelected.Count = 0 Then
      strTitle = "No items selected"
      strPrompt = "Please select at least one item"
      MsgBox prompt:=strPrompt, _
         buttons:=vbInformation + vbOKOnly, _
         Title:=strTitle
      lst.SetFocus
      GoTo ErrorHandlerExit
   End If
   
   intColumns = lst.ColumnCount
   intRows = lst.ItemsSelected.Count
   strTitle = "Information missing"
   
   'Test for required information, using listbox columns
   For Each varItem In lst.ItemsSelected
      'Check for required address information (or whatever you need to check)
      strTest = Nz(lst.Column(5, varItem))
      Debug.Print "Street address: " & strTest
      If strTest = "" Then
         strPrompt = "Skipping this record -- no street address!"
         MsgBox prompt:=strPrompt, _
            buttons:=vbExclamation + vbOKOnly, _
            Title:=strTitle
         GoTo NextItem
      End If
      
      'Do something with info from the listbox columns, using
      'this syntax
      strData = Nz(lst.Column(5, varItem))
      
NextItem:
   Next varItem

ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & "; Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 34961874
"OnEnter" refers to when a control received focus. In other words, when you tab into it or click inside of it with a mouse (where the cursor was in some other control just prior), OnEnter should fire. OnEnter does not refer to the pressing of the "Enter" key. You would need to handle OnKeyPress, OnKeyUp, or OnKeyDown to check for the pressing of an enter key.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34961883
If you want to stick with a subform, the Current event is also a possibility.  It fires when you select a row.
0
 

Author Closing Comment

by:pdvsa
ID: 34962182
ON "Key Up" seemed to be the quick fix.  

thanks...
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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