Modify 'You must enter a value in the 'XXX' field (Access 2010)

Hi Experts,

I'm having difficulty finding a resource for error handling that I actually understand.  If I wanted to modify the message 'You must enter a value in the 'XXX' field, how would I go about it?

I would just like to change the text message that displays and have an OK button while eliminating the  'Help' button that shows.

Thanks!
grmcraAsked:
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.

Barry CunneyCommented:
For general error handling you would do something like the below

Sub FormSave

On Error GoTo errHandler

...

  Exit Sub
errHandler:
  MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
   VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"
End Sub


For validating input on a form and giving a very customized message you may have to write some customized code behind a save button that validates user imput
0
Dale FyeCommented:
Generally, the best way to accomplish this is to do your own testing in the Form_BeforeUpdate event.  The syntax might look like:

Private Sub Form_BeforeUpdate(Cancel as Integer)

    If me.txtControl1 & "" = "" Then
         msgbox "Enter a valid response for 'Control1'"
         me.txtControl1.setfocus
         Cancel = true
    Elseif me.txtControl2 & "" = "" Then
         msgbox "Enter a valid response for 'Control2'"
         me.txtControl2.setfocus
         Cancel = true
    End If

End sub

The tests (me.txtControl1 & "" = "") evaluate whether a required control either contains a NULL or has a zero length string.  You can add other tests in there as well, for example, you might want to confirm that a control contains a numeric value, or a date as well.

I usually create my forms with a "Save" button and put this code in the Click event of the save button, but to do this, you have to disable the other methods that might allow the user to close the form or move off the current record (disable navigation buttons), disable the abilito of the scroll button on the mouse to change records (before A2007), disable the form close button, ...
1

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
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.