Solved

Cancel enter key on the after update event

Posted on 2014-11-14
10
26 Views
Last Modified: 2015-11-11
When I hit the enter key in a field the after update event is triggered and form with a listview opens. I want first row in listview to have focus when it's open but that creates a problem. It's seems like the keycode from the enter key  still comes to action and automatically select the first row in listview and the form closes.  Can I someway trap or cancel the behavior from the enter key? I have tried to set the keycode to 0, but its look like the enter key comes to play after all code is done.
0
Comment
Question by:hallpett
  • 4
  • 4
  • 2
10 Comments
 
LVL 10

Expert Comment

by:Gozreh
Comment Utility
Can you please write your example code on afterupdate event ? How are you triggering to open the listview form ?
0
 

Author Comment

by:hallpett
Comment Utility
Afterupdate code:

Private Sub SlakteDato_AfterUpdate()
Dim stDocName As String
    
    stDocName = OppslagsForm
    DoCmd.OpenForm stDocName, acNormal, , , , acWindowNormal    
    
End Sub

Open in new window


Form with listview is named "OppslagsForm"
In the load event of this form I have this code:
Private Sub Form_Load()
    
    Call FillListView1
    lstListView1.SetFocus 'Focus on first row in listview

End Sub

Open in new window


When row is selcted by doubleclick or enter I Close the form and to some other stuff. My problem is that the enter stroke that triggered the afterupdate event comes to use and select the first row in the listview as soon as the listview formed is opened and thereby close it at once.
0
 
LVL 10

Expert Comment

by:Gozreh
Comment Utility
When row is selcted by doubleclick or enter I Close the form and to some other stuff.
Are you using OnEnter event to close form ?
0
 

Author Comment

by:hallpett
Comment Utility
I'm this this event/code to close form:
Private Sub lstListView1_KeyUp(KeyCode As Integer, ByVal Shift As Integer)
    If KeyCode = 13 Then
    	DoCmd.Close acForm, "frmSlakteregistreringOppslagDisp"
	... some action
                  ... more action
    End If
End Sub

Open in new window

0
 
LVL 10

Expert Comment

by:Gozreh
Comment Utility
You can use the KeyDown
Private Sub lstListView1_KeyDown(KeyCode As Integer, Shift As Integer)
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
try

* set the Forms Key Preview property to Yes (in the Event tab) of the form
* use the Form event

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then KeyCode =0

End sub
0
 
LVL 10

Expert Comment

by:Gozreh
Comment Utility
Private Sub lstListView1_KeyDown(KeyCode As Integer, ByVal Shift As Integer) 
    If KeyCode = 13 Then
    	DoCmd.Close acForm, "frmSlakteregistreringOppslagDisp"
	... some action
                  ... more action
    End If
End Sub

Open in new window

0
 

Accepted Solution

by:
hallpett earned 0 total points
Comment Utility
Tried your solutions, but same problem no matter what. Solved it by using a private variable so that I could controll the first key event after opening of the form.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
@hallpett,

post the solution that solved your problem so that others which might have the same problem may benefit too.
0
 

Author Closing Comment

by:hallpett
Comment Utility
-
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

772 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

9 Experts available now in Live!

Get 1:1 Help Now