Table's Required Properties for field not enforced on form

  • Thread starter Thread starter louonline
  • Start date Start date
L

louonline

Hello again,
I have a textbox on a form and at table level the settings for it are
as follows......
Data Type = text
Field Length = 1
Required = YES
Allow Zero length = NO
I assumed that with these settings (when in the form tied to this
table) you MUST enter data into this field (once it gets the focus)
before you can move to the next field.
For some reason I can hit Tab or Enter and no error warning is
generated that this field cannot be left empty/null and can just move
on to the next field.
It appears the Required and Zero Length Properties settings for this
field in the Table are completely ignored!
At form level I have no Events inserted for this field.
I have checked spelling.
Run the DB on three different computers, same result.

Now here is the queer part; if I DO enter a letter (or anything) in
this field and then delete it, the table settings spring into action
and the standard MS message informing me that this field must have
data and cannot be left null is displayed!


Is there any `form event' that can override the settings in the
table?
I am under the impression that settings in the table take precedence
above all else perhaps (most likely) I'm wrong.
I don't want to start playing around with form events if there may be
some other reason for this strange behaviour.
BTW, this is not related to my previous post regarding automatically
clearing a field.
Any help would be appreciated.

Regards,
Lou
 
Lou, the settings you have make perfect sense, and you will not be able to
*save* any record in your form unless you enter a value for this field.

However, just because you visit the field does not mean you must start
entering something at that point. You can click the the text box, and
(provided you don't start entering something), you can then click somewhere
else. You won't be able to save the record, but you are not forced to enter
it before you can get out of the box and into another control.

But the database engine will still reject the record unless there is
something in this field. (If this does not happen, you probably have a
Default Value set.)
 
Thanks for the confirmation Allen.
Since my posting I've done some further reading and found out that's
how it works.
that gives you an idea how raw I am.
I've never used that property before so I assumed that it came into
action as soon as the field lost the focus and nothing was entered
into it.
Logically one would assume that's how it would work but then again my
old brain may not be 'computer logical'.
Is there a funtion that will not let you leave a required field empty
once you have tabbed into it or it gets the focus?

Regards,
Lou
 
You could cancel the control's Exit event if you are desperate.

I suggest you don't though. Instead learn to work with the events Access
gives you. If you are thinking procedurally (this will happen and then
that), you need to change your mindset to think event-driven (when this
happens, it will bring that response.)
 
LOL Allen,
You're right about my mind set, must be my age :)
But just as a matter of interest, how would a cancel the control's Exit
event?

Regards,
Lou
 
Set the control's On Exit property to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.
The event procedure declaration includes a Cancel argument.
You can thefore enter:
Cancel = True
and the user can never get out of the control.
In practice, you would code:
If IsNull(Me.[NameOfYourControlHere]) Then
Cancel = True
End If

If you prefer to use a macro, use the CancelEvent action.
 
Thanks Allen,
I've been playing around and this is what I came up with...
-----------------------------------------------------
Private Sub SOME_ID_FIELD_Exit(cancel As Integer)
If IsNull(SOME_ID_FIELD) Then
MsgBox "You MUST enter something in here"
cancel = True
End If
End Sub
----------------------------------------------------
It seems to do the job OK.

I am now wondering what the pitfalls are by not using Me.[ ]
as per your sample.....(Me.[NameOfYourControlHere])

Regards,
Lou
 
Use of Me is optional. Personally, I always use it since:
a) it provides the context (so the reference cannot be misunderstood as
something else),
b) it triggers the intellisense so Access auto-completes the name, and I am
less likely to misspell it.

The square brackets are also optional, unless the name contains a space or
other strange character, or starts with a number. I never use those field
names, so never bother with the square brackets.

The code you posted looks just right, but I would still not buy your program
if you wrote it that way. :-)
 
Back
Top