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
Solved

Cancel enter key on the after update event

Posted on 2014-11-14
10
31 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
ID: 40442439
Can you please write your example code on afterupdate event ? How are you triggering to open the listview form ?
0
 

Author Comment

by:hallpett
ID: 40442461
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
ID: 40442497
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:hallpett
ID: 40442517
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
ID: 40442542
You can use the KeyDown
Private Sub lstListView1_KeyDown(KeyCode As Integer, Shift As Integer)
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40442557
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
ID: 40442594
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
ID: 40447004
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41198524
@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
ID: 41225705
-
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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 utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

839 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