Could you make use of the "Validation Rule" property of the control ?
Validation Rule: ="Y" Or ="N"
Validation Text: Value must be Y or N
Main Topics
Browse All TopicsI 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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: EWHTLCPosted on 2007-06-08 at 04:14:12ID: 19240871
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