Solved

ON Enter

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

929 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

10 Experts available now in Live!

Get 1:1 Help Now