Checking for required fields

  • Thread starter Thread starter Mantok
  • Start date Start date
M

Mantok

I am running ACCESS 97 and can not set the require field
tag on this table. So I added code to check for required
fields on the click event of the Submit button. When I
run the form in debug mode, I can see the value of
cmbFirst in NULL. But when I tried checking "If cmbFirst
= NULL Then", it didn't trap it. So I tried the
following, but it doesn't trap them either.

Procedure cmdSubmit_click
If (cmbFirst < " " Or txtSecond < " " Or lstThird
< " ") Then
If cmbFirst < " " Then
lblFirst.ForeColor = 255
End If
If txtSecond < " " Then
lblSecond.ForeColor = 255
End If
If lstThird < " " Then
lblThird.ForeColor = 255
End If
MsgBox ("Required Fields not entered")
GoTo Exit_cmdSubmit_Click
End If
 
Your best bet would be to find out why you can not set the Required
attribute of the field in the table. Then you won't need any code. And it
will automatically work for every form. But you have not told us what the
problem was there, so we can not offer many suggestions!

To check for Null in code, you need to do this:

if isnull (whatever) then ...

None of these will ever work:

if whatever = null then ...
if whatever <> null then ...
if null = null then ...
if null <> null then ...

Null is, by definition, an "unknown value". An "unknown" value can not, by
definition, be equal to (or not equal to) any other known value. If you knew
that the unknown value was equal to (or not equal to) some known value,
then, you >would< know something about the "unknown" value - and that is
logically impossible.

HTH,
TC
 
Your best bet would be to find out why you can not set
the Required
attribute of the field in the table.

It is because the current data doesn't have information in
some of the fields.

Sorry to ask such a simple question. The Nz function
works as well.
 
Back
Top