We help IT Professionals succeed at work.

access 2003 form Error 2467

Eric Harris
Eric Harris asked
on
1,661 Views
Last Modified: 2013-12-05
I have a text box which I validate as "must be equal to Y or N" in a Before update procedure.
I the check fails I use a cancel = true.
This works fine if the user presses the enter or tab keys
The user may however press a function key (form keydown).

When this happens the validation process kicks in and the msgbox error message is displayed (vbcritical).
However, when the user clicks OK, an error message is displayed -

run time error 2467
The expression you entered refers to an object that is closed or doesn't exist.

Any ideas how to trap this error or work around it
Comment
Watch Question

Eric HarrisDeveloper

Author

Commented:
further to my previoius comment. Here's my code

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Call keystring(KeyCode, keystr, Shift)

If keystr = "F2" Or _
   keystr = "F3" Or _
   keystr = "F4" Or _
   keystr = "F5" Or _
   keystr = "F8" Or _
   keystr = "F9" Or _
   keystr = "F11" Or _
   keystr = "F12" Then
  Set ctl = Screen.ActiveControl
  If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
    strtext = ctl.Text
    stroldval = ctl.OldValue
    If Not strtext = stroldval Then
      KeyCode = 0
      MsgBox "You are in the middle of changing data - please complete this before pressing any function keys", vbCritical, "Error"
      MsgBox stroldval
      MsgBox strtext
      GoTo keyend
    End If
  End If
End If
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Eric HarrisDeveloper

Author

Commented:
works for some of my instances and I've managed to get a workaround for the others.
Thanks for your help
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.