Solved

ON Enter

Posted on 2011-02-23
5
260 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 74

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now