?
Solved

ON Enter

Posted on 2011-02-23
5
Medium Priority
?
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

752 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