Trapping ENTER key in keydown event

I'm fairly new to working with Access 2000 and have run into the following problem.  I have a SUBFORM with a number of controls (Date, listbox, text).  For speeding up Data entry, I have allowed the use of the ENTER key on each control.  I test for this in the KEYDOWN event for that control.  If the ENTER key was pressed, I call a subroutine that does some field edits, sets visible = false for the active subform and visible = true for the next data entry subform.  My problem is that ACCESS field validation seems to occur after the KEYDOWN event and I therefore receive an error when I try to set the focus to the next subform.  Is there a way to have ACCESS do the field validations from within or prior to the KEYDOWN event?  I would cancel the call to my subroutine if there were any errors.  Current code follows:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   If KeyCode = vbKeyReturn Then
      cbExit.SetFocus <-- required to pickup changed data in control  ** ERROR occurs here **
      ProcessEntry
      KeyCode = 0
   ElseIf KeyCode = vbKeyF3 Then
      cbExit.SetFocus
      KeyCode = 0
      cbExit_Click
   End If
End Sub

Any help would be appreciated.  Thanks.  
LVL 1
inkineuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1WilliamCommented:
Instead of doing field validatation in the table, you ought to do it in the form.  Try it and you'll find your troubles disappear!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DrTechCommented:
Try using the AfterUpdate event instead.
0
inkineuAuthor Commented:
re suggestion: Field validation in the Form.  Would this mean removing the Format property from all Controls (date format = blank, listbox setting LIMIT to List = No)?

re suggestion: Use AfterUpdate event.  How would I trap the ENTER key in the AfterUpdate event?

Forgot to mention that the controls are all Temporary fields (Control Source property = blank) and do not exist in a Table.  I manipulate the data entered and then update a number of Tables using code.  

Thanks again.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

1WilliamCommented:
No, it means on the after update event/lost focus (which would occur upon pressing the enter key, to have some code to confirm/validate the data
0
inkineuAuthor Commented:
The KeyDown event occurs before the AfterUpdate event.  I need to move the focus to another control so that the value in the current control is activated (found this out the hard way).  In the KeyDown event I come up with the error:
Run-time error 2110: cannot move focus to the control cbExit.
This happens when I enter an invalid Date in a control where the Format is set to Short Date.  Seems to me that at this point Access knows there's an invalid date but gives control to the KeyDown event.  Hope this makes sense.
If I remove the FORMAT Short Date and instead do my own validation using IsDate, it works.  
0
1WilliamCommented:
It does make sense.  I had a suspicion that you problem was what you had described.  Not duplicating it I could not be positive, but I was sure that the issue was when the data was being validated.  You may want to use an input mask on the date field, at least the user will have to enter some sort of a date, might reduce the number of times your validatation rags on the user.
0
inkineuAuthor Commented:
Shall do.  One last thing, what's the best thing to use for my listbox validation, as I will need to remove the NOTINLIST event?
0
1WilliamCommented:
Well, being the user cannot type into a list box (only select), what validation can there be?
0
inkineuAuthor Commented:
Sorry, I meant combo box.
0
1WilliamCommented:
Access will do it for you.  If you need to validate (is, a value that is in the combo but not correct for other choices the user has made), do it in the after update event
0
inkineuAuthor Commented:
The problem is the same as the Date problem.  Same error message.  I need to set the limit to list = No and do my own validation.
0
1WilliamCommented:
Is the combo being populated from a table, value list?
0
inkineuAuthor Commented:
I'm going to use the DLookup function.
Thanks for your help.
0
1WilliamCommented:
I had a few thoughts on your combo NotInList-Data validatation:

Private Sub Combo22_NotInList(NewData As String, Response As Integer)

    If MsgBox("Hey, wadda ya doin'?", 37) = 2 Then   ' Not going to select a value at this time
        Me.Combo22.Undo             ' Clear the value
        SendKeys "{TAB}"            ' Go to the next control in the tab order
    Else                            ' They are going to pick a choice from the list
        MsgBox "Like, you must enter or select a valid choice from this list!", vbExclamation
    End If
   
    Response = acDataErrContinue
   
End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.