Deleting New Record

P

Pierre

Morning/Evening all,

Is there a way to keep a new record from being created if a field is not
filled in? I have set the [Given_Name] property to a required field,
thinking that if it was left blank the record would not remain. What I’m
getting is an error stating “The Field ‘All info.Given_Name’ cannot contain a
Null value because the Required property for this field is set to True.
Enter a value in this field.†At this point I’m not able to move to another
record unless I add a name.

Any and all suggestions are greatly appreciated.
 
D

Dirk Goldgar

Pierre said:
Morning/Evening all,

Is there a way to keep a new record from being created if a field is not
filled in? I have set the [Given_Name] property to a required field,
thinking that if it was left blank the record would not remain. What I’m
getting is an error stating “The Field ‘All info.Given_Name’ cannot
contain a
Null value because the Required property for this field is set to True.
Enter a value in this field.†At this point I’m not able to move to
another
record unless I add a name.

Any and all suggestions are greatly appreciated.


At that point, you have to undo the record so that Access no longer thinks
it's "dirty". Press the Escape ("Esc") key once or twice to completely undo
the record (if you have a "dirty " control, the first Escape undoes the
control, and the second undoes the form).
 
A

Allen Browne

Just press <Esc> twice to undo the new record.

If you want to programmatically trap the error, use the form's Error event.

You may also be able to cancel the form's BeforeUpdate event (not that of
the control.)
 
P

Pierre

how would I go about programmatically traping the error so that that I don't
have to hit the <ESC>
--
Work is sometimes hard....but someone has to do it.


Allen Browne said:
Just press <Esc> twice to undo the new record.

If you want to programmatically trap the error, use the form's Error event.

You may also be able to cancel the form's BeforeUpdate event (not that of
the control.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pierre said:
Morning/Evening all,

Is there a way to keep a new record from being created if a field is not
filled in? I have set the [Given_Name] property to a required field,
thinking that if it was left blank the record would not remain. What I’m
getting is an error stating “The Field ‘All info.Given_Name’ cannot
contain a
Null value because the Required property for this field is set to True.
Enter a value in this field.†At this point I’m not able to move to
another
record unless I add a name.

Any and all suggestions are greatly appreciated.
 
A

Allen Browne

Form_Error lets you trap the error, but it does not avoid it. You do need to
train whoever is entering this to use <Esc> to undo an entry they don't
want. (They can use Undo on the toolbar or in the menu if you prefer.)

If you really want to avoid the error, you may be able to use

1. Select the Form, and in the properties box, set its Before Update event
property to
[Event Procedure]

2. Click the Build button (...) beside this.
Access opens the code window.

3. Set up the code like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Given_Name) Then
Cancel = True
MsgBox "Enter the Given Name, or press <Esc> to undo."
End If
End Sub

If you don't want the message, you can replace the MsgBox line with:
Me.Undo
This just destroys whatever the user typed, but gives them no idea why it
didn't work. They may not even know that it didn't work. Bad idea.

If the person is actually in the Given_Name box when they try to save the
record, and they entered something and then backspaced it out, they still
get the original error. You would need to take a different tac to solve
this: leave the field's Required property as No, and settting a Validation
Rule on the *table* (not field) of:
[Given_Name] Is Not Null

But the core concept is that if the entry is not acceptable, you do have to
tell the user what's wrong so they can choose to fix it or give up on the
entry.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pierre said:
how would I go about programmatically traping the error so that that I
don't
have to hit the <ESC>
--
Work is sometimes hard....but someone has to do it.


Allen Browne said:
Just press <Esc> twice to undo the new record.

If you want to programmatically trap the error, use the form's Error
event.

You may also be able to cancel the form's BeforeUpdate event (not that of
the control.)

Pierre said:
Morning/Evening all,

Is there a way to keep a new record from being created if a field is
not
filled in? I have set the [Given_Name] property to a required field,
thinking that if it was left blank the record would not remain. What I’m
getting is an error stating “The Field ‘All info.Given_Name’ cannot
contain a
Null value because the Required property for this field is set to True.
Enter a value in this field.†At this point I’m not able to move to
another
record unless I add a name.

Any and all suggestions are greatly appreciated.
 
P

Pierre

TY - your suggestion was vary helpful and utilized


--
Work is sometimes hard....but someone has to do it.


Allen Browne said:
Form_Error lets you trap the error, but it does not avoid it. You do need to
train whoever is entering this to use <Esc> to undo an entry they don't
want. (They can use Undo on the toolbar or in the menu if you prefer.)

If you really want to avoid the error, you may be able to use

1. Select the Form, and in the properties box, set its Before Update event
property to
[Event Procedure]

2. Click the Build button (...) beside this.
Access opens the code window.

3. Set up the code like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Given_Name) Then
Cancel = True
MsgBox "Enter the Given Name, or press <Esc> to undo."
End If
End Sub

If you don't want the message, you can replace the MsgBox line with:
Me.Undo
This just destroys whatever the user typed, but gives them no idea why it
didn't work. They may not even know that it didn't work. Bad idea.

If the person is actually in the Given_Name box when they try to save the
record, and they entered something and then backspaced it out, they still
get the original error. You would need to take a different tac to solve
this: leave the field's Required property as No, and settting a Validation
Rule on the *table* (not field) of:
[Given_Name] Is Not Null

But the core concept is that if the entry is not acceptable, you do have to
tell the user what's wrong so they can choose to fix it or give up on the
entry.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pierre said:
how would I go about programmatically traping the error so that that I
don't
have to hit the <ESC>
--
Work is sometimes hard....but someone has to do it.


Allen Browne said:
Just press <Esc> twice to undo the new record.

If you want to programmatically trap the error, use the form's Error
event.

You may also be able to cancel the form's BeforeUpdate event (not that of
the control.)

Morning/Evening all,

Is there a way to keep a new record from being created if a field is
not
filled in? I have set the [Given_Name] property to a required field,
thinking that if it was left blank the record would not remain. What I’m
getting is an error stating “The Field ‘All info.Given_Name’ cannot
contain a
Null value because the Required property for this field is set to True.
Enter a value in this field.†At this point I’m not able to move to
another
record unless I add a name.

Any and all suggestions are greatly appreciated.
 

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