Trapping Enter Key No Longer Working

D

Dave

We just migrated to 2007 from 2003. I swear that before the migration, the Keypress event for a textbox fired and the code inserted a carriage return & line feed when the user pressed the Enter key on that control. Now it does not, and I have tried all day to fix this (added 2 more events to test) and can report the following:

the form is bound; Keypreview is set to Yes; all form command buttons are set to Default-no and Cancel-no; swapped keyboards (desperate! no change)

press a T key...
1) KeyDown: KeyAscii=0, KeyCode=84
2) KeyPress: KeyAscii=166, KeyCode="Empty"
3) KeyUp does not fire.

press Enter key...
1) KeyDown: KeyAscii=0, KeyCode=0
2) KeyPress & KeyUp don't fire

This is the pertinent part that worked before, but will never work now thatthe KeyAscii value being returned is always 0:
If KeyAscii = 13 Then
If Me.Dirty = True Then Me.Dirty = False 'user may have deleted alltext so force save on field
If IsNull(txtShipReason) Then Exit Sub 'if field is now null, exit sub
lngPos = Len(txtShipReason) 'determine number of characters
txtShipReason.SelStart = lngPos 'move to the end of the text
SendKeys "^{ENTER}" 'enter the line wrap
End If
I'm stumped! Could it be the migration? I have been working on opening thisform in various modes (view, new, edit) and wonder if it could have something to do with form properties such as AllowEdits. HOWEVER, before you jumpon that one, this coded no longer works in the current production version of the database either, which was in use before the migration. Any ideas out there?
 
D

Douglas J Steele

You shouldn't need any code. Just change the EnterKeyBehavior property of
the text box.


"Dave" wrote in message

We just migrated to 2007 from 2003. I swear that before the migration, the
Keypress event for a textbox fired and the code inserted a carriage return &
line feed when the user pressed the Enter key on that control. Now it does
not, and I have tried all day to fix this (added 2 more events to test) and
can report the following:

the form is bound; Keypreview is set to Yes; all form command buttons are
set to Default-no and Cancel-no; swapped keyboards (desperate! no change)

press a T key...
1) KeyDown: KeyAscii=0, KeyCode=84
2) KeyPress: KeyAscii=166, KeyCode="Empty"
3) KeyUp does not fire.

press Enter key...
1) KeyDown: KeyAscii=0, KeyCode=0
2) KeyPress & KeyUp don't fire

This is the pertinent part that worked before, but will never work now that
the KeyAscii value being returned is always 0:
If KeyAscii = 13 Then
If Me.Dirty = True Then Me.Dirty = False 'user may have deleted all text
so force save on field
If IsNull(txtShipReason) Then Exit Sub 'if field is now null, exit sub
lngPos = Len(txtShipReason) 'determine number of characters
txtShipReason.SelStart = lngPos 'move to the end of the text
SendKeys "^{ENTER}" 'enter the line wrap
End If
I'm stumped! Could it be the migration? I have been working on opening this
form in various modes (view, new, edit) and wonder if it could have
something to do with form properties such as AllowEdits. HOWEVER, before you
jump on that one, this coded no longer works in the current production
version of the database either, which was in use before the migration. Any
ideas out there?
 
D

Dave

You shouldn't need any code. Just change the EnterKeyBehavior property of
the text box.

"Dave"  wrote in message


We just migrated to 2007 from 2003. I swear that before the migration, the
Keypress event for a textbox fired and the code inserted a carriage return &
line feed when the user pressed the Enter key on that control. Now it does
not, and I have tried all day to fix this (added 2 more events to test) and
can report the following:

the form is bound; Keypreview is set to Yes; all form command buttons are
set to Default-no and Cancel-no; swapped keyboards (desperate! no change)

press a T key...
1) KeyDown: KeyAscii=0, KeyCode=84
2) KeyPress: KeyAscii=166, KeyCode="Empty"
3) KeyUp does not fire.

press Enter key...
1) KeyDown: KeyAscii=0, KeyCode=0
2) KeyPress & KeyUp don't fire

This is the pertinent part that worked before, but will never work now that
the KeyAscii value being returned is always 0:
If KeyAscii = 13 Then
    If Me.Dirty = True Then Me.Dirty = False 'user may have deleted all text
so force save on field
    If IsNull(txtShipReason) Then Exit Sub 'if field is now null, exit sub
    lngPos = Len(txtShipReason) 'determine number of characters
    txtShipReason.SelStart = lngPos 'move to the end of the text
    SendKeys "^{ENTER}" 'enter the line wrap
End If
I'm stumped! Could it be the migration? I have been working on opening this
form in various modes (view, new, edit) and wonder if it could have
something to do with form properties such as AllowEdits. HOWEVER, before you
jump on that one, this coded no longer works in the current production
version of the database either, which was in use before the migration. Any
ideas out there?

Sorry, I neglected to mention that I already had that property set. In
a new textbox, I tried it with that setting, which does not line wrap
even with ctrl>Enter. I am going to add a test form to play with this.
If it works, maybe it's an AllowEdits/Deletions/Additions or DataEntry
setting on the form. If not, I will create a new db and try that. Any
other ideas?
 
P

Phil Hunt

It is probably the SendKey. It is not 100% reliable to begin with.


You shouldn't need any code. Just change the EnterKeyBehavior property of
the text box.

in message


We just migrated to 2007 from 2003. I swear that before the migration, the
Keypress event for a textbox fired and the code inserted a carriage return
&
line feed when the user pressed the Enter key on that control. Now it does
not, and I have tried all day to fix this (added 2 more events to test)
and
can report the following:

the form is bound; Keypreview is set to Yes; all form command buttons are
set to Default-no and Cancel-no; swapped keyboards (desperate! no change)

press a T key...
1) KeyDown: KeyAscii=0, KeyCode=84
2) KeyPress: KeyAscii=166, KeyCode="Empty"
3) KeyUp does not fire.

press Enter key...
1) KeyDown: KeyAscii=0, KeyCode=0
2) KeyPress & KeyUp don't fire

This is the pertinent part that worked before, but will never work now
that
the KeyAscii value being returned is always 0:
If KeyAscii = 13 Then
If Me.Dirty = True Then Me.Dirty = False 'user may have deleted all text
so force save on field
If IsNull(txtShipReason) Then Exit Sub 'if field is now null, exit sub
lngPos = Len(txtShipReason) 'determine number of characters
txtShipReason.SelStart = lngPos 'move to the end of the text
SendKeys "^{ENTER}" 'enter the line wrap
End If
I'm stumped! Could it be the migration? I have been working on opening
this
form in various modes (view, new, edit) and wonder if it could have
something to do with form properties such as AllowEdits. HOWEVER, before
you
jump on that one, this coded no longer works in the current production
version of the database either, which was in use before the migration. Any
ideas out there?

Sorry, I neglected to mention that I already had that property set. In
a new textbox, I tried it with that setting, which does not line wrap
even with ctrl>Enter. I am going to add a test form to play with this.
If it works, maybe it's an AllowEdits/Deletions/Additions or DataEntry
setting on the form. If not, I will create a new db and try that. Any
other ideas?
 
D

Dave

It is probably the SendKey. It is not 100% reliable to begin with.









Sorry, I neglected to mention that I already had that property set. In
a new textbox, I tried it with that setting, which does not line wrap
even with ctrl>Enter. I am going to add a test form to play with this.
If it works, maybe it's an AllowEdits/Deletions/Additions or DataEntry
setting on the form. If not, I will create a new db and try that. Any
other ideas?- Hide quoted text -

- Show quoted text -

Solved it, and it's embarrassing. I had form level code designed to
permit normal Enter key behaviour everywhere else by setting the Ascii
value to 0. My understanding is that in our former version of Access,
the keypress event on the textbox would follow the event at the form
level, thus would recognize the value of 13. As I said, it was working
before. In the version I'm revising, the 0 value was propagating to
the textbox event. Not sure if I screwed that up with improper value
referencing, or if it's connected to the version migration. In any
event, I feel better if I blame it on the on-again/off-again allotment
of time I'm permitted to do this stuff. It's been weeks since I worked
on the changes I started long before we migrated to 2007.
Thanks to all for your suggestions!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top