require value error message

E

EddWood

Hi Guys,

I have a form of which one of the fields is a required field and just
wondering how/ where I put the code to present a message box if they fail to
enter a value. I was going to use:


If MsgBox("This is a required field, " & _
"Have you entered some details?.", vbYesNo) = vbYes Then
End If

But am unsure where I should place this? I am using a SQL BE with Access FE
and currently if the user tries to leave the field blank they get a very
unfriendly error message.

Can anyone advise please
 
L

Linq Adams via AccessMonster.com

Well, you don't validate whether or not a control has data in it by asking
the user, you check the control:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.YourTextBoxName = "" Or IsNull(Me.YourTextBoxName) Then
MsgBox "You Must Fill In the " & YourTextBoxName & " Field!"
Cancel = True
YourTextBoxName.SetFocus
End If
End Sub
 

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

Top