Solved

ON Enter

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

756 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