hallpett
asked on
Cancel enter key on the after update event
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.
Can you please write your example code on afterupdate event ? How are you triggering to open the listview form ?
ASKER
Afterupdate code:
Form with listview is named "OppslagsForm"
In the load event of this form I have this code:
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.
Private Sub SlakteDato_AfterUpdate()
Dim stDocName As String
stDocName = OppslagsForm
DoCmd.OpenForm stDocName, acNormal, , , , acWindowNormal
End Sub
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
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.
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 ?
ASKER
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
You can use the KeyDown
Private Sub lstListView1_KeyDown(KeyCo de As Integer, Shift As Integer)
Private Sub lstListView1_KeyDown(KeyCo
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
* 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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@hallpett,
post the solution that solved your problem so that others which might have the same problem may benefit too.
post the solution that solved your problem so that others which might have the same problem may benefit too.
ASKER
-