Keydown Event while in a data Entry Field

S

stickandrock

I have a Keydown event checking for F10 on a data entry form.

In my form I have 10 data entry fields. Let say I put data in the first 5
and after typing in the 6th (without moving out of the field) I hit the F10
key. The F10 logic processing only recognizes the values in fields 1-5 and
nothing in field 6. I there a way to commit the values that were started to
be typed in Field 6 in the start of the logic of the F10 keydown event.

Thanks,
Don
 
S

stickandrock

OK I figured out a work around, but I would still like to hear of other ways
of accomplishing the same thing.

my workaround:
After I have confirmed the F10 was pressed and before I call my function to
process the record - I set.focus on another field on the form.

Thanks,
D
 
T

tighe

i have used: DoCmd.RunCommand (acCmdSaveRecord)
this can be used lots of places and you won't have to worry about knowing
other fields to set a focus on.

you still would want to run this before the rest of the process.

hope this helps.
 
D

Dirk Goldgar

stickandrock said:
I have a Keydown event checking for F10 on a data entry form.

In my form I have 10 data entry fields. Let say I put data in the first 5
and after typing in the 6th (without moving out of the field) I hit the
F10
key. The F10 logic processing only recognizes the values in fields 1-5
and
nothing in field 6. I there a way to commit the values that were started
to
be typed in Field 6 in the start of the logic of the F10 keydown event.


Because the focus hasn't yet moved off the control, the text that has been
typed in the control hasn't yet been committed, so the control's value is
unchanged. Something like this might work, though I haven't really tested
it:

'------ start of example code ------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Dim ctl As Access.Control

If KeyCode = vbKeyF10 Then

' Swallow this key so it doesn't get processed afterward.
KeyCode = 0

' Try to get a reference to the form's active control.
' If there isn't one, ignore the error.
On Error Resume Next
Set ctl = Me.ActiveControl
On Error GoTo 0

' Only continue if we had an active control.
If Not ctl Is Nothing Then

With ctl
' Make sure the control is one of the ones I want
' to handle this way.

If .Name = "txtField1" _
Or .Name = "txtField2" _
Or .Name = "txtField3" _
Then

' If anything has been entered in the control,
' force that value to be committed.
' If the control text is blank, set the value to Null.
If Len(Trim(ctl.Text)) > 0 Then
ctl.Value = ctl.Text
Else
ctl.Value = Null
End If

End If

End With

Set ctl = Nothing

End If

' Here you do whatever you were originally
' going to do whenever the F10 key is pressed.

End If

End Sub
'------ end of example code ------
 

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

Similar Threads


Top