if...then...else procedure not working - object required message

  • Thread starter Thread starter Richard Rueda via AccessMonster.com
  • Start date Start date
R

Richard Rueda via AccessMonster.com

Hi there

I am currently working on a database project which involves some custom
message boxes. What I am trying to do is check to see whether a field is
null when the save record, next, previous or exit button is clicked.

I believe the general formula is somthing like this

If Forms![Form Name]![Field Name] is Null then Msgbox("Please enter a name
into this field") else continue with the normal code

It compiles ok but when I go to run it a message box appears saying "Object
Required" but not what I want it to do which is for a message box to appear
saying that you must enter something into the field.

I have chosen to put the code on the click of the buttons so that when they
are clicked they cannot carry out their normal function until the field is
filled it therefore not allowing an empty field to be stored into the
database.


I thank you very much in advanced any help is greatly appreciated

Richard
 
Try:

If IsNull(Forms![Form Name]![Field Name]) Then
Msgbox("Please enter a name into this field")
 
Always post exact copy of your code... nothing worse than providing a
solution to the wrong problem.

You need to use the IsNull function instead of "Is Null":

If IsNull(Forms![Form Name]![Field Name]) then
Msgbox("Please enter a name into this field")
Else
' code
End If
 
Back
Top