Close form w/o "can not contain a null value"

D

Dennis

Hi,

I and running Access via XP Office Pro w/ sp3 on XP Pro w / sp3.

I have a simple data entry form. When I am done doing my data entry, I am
on a blank screen / new record. As this point I was to close the form, but
when I do I received the error message:

The field “tbl.Warranty.ItemName†cannot contain a Null value because the
Required property for this field is set to true. Enter a value in this
field.â€

Obviously, Access is trying to write a blank record when I close the
program. How do I prevent this from happing?

I would like to use both the Window Close (X) button and a Close button
control to close my window.

How do I close my form cleanly without getting the above error message?

I believe that somehow I have to use Me.NewRecord,


Thanks


Dennis
 
M

Marshall Barton

Dennis said:
I and running Access via XP Office Pro w/ sp3 on XP Pro w / sp3.

I have a simple data entry form. When I am done doing my data entry, I am
on a blank screen / new record. As this point I was to close the form, but
when I do I received the error message:

The field “tbl.Warranty.ItemName” cannot contain a Null value because the
Required property for this field is set to true. Enter a value in this
field.”

Obviously, Access is trying to write a blank record when I close the
program. How do I prevent this from happing?

I would like to use both the Window Close (X) button and a Close button
control to close my window.

How do I close my form cleanly without getting the above error message?


That message usually means that your "blank" new record
actually has some data that Access is trying to save.

That can happen if you type a space in a text box. The
space is the data to be saved, but some other field requires
data before the record can be saved.

Another, more common, reason is that you have some code
(probably in the form's Current event) that is setting the
value of a bound control. That value then needs to be
saved, etc.
 
D

Dennis

Marshall,

You are correct once again.

I found where I initialize a value on the form, which is tied to a field
(Control Source) on the record. How can I initialize the field on the form
without initializing the record's field. Do I have to "unbind" the record
field from the control and then manually assign a value to the record's field
or is there another way?
 
M

Marshall Barton

Dennis said:
Marshall,

You are correct once again.

I found where I initialize a value on the form, which is tied to a field
(Control Source) on the record. How can I initialize the field on the form
without initializing the record's field. Do I have to "unbind" the record
field from the control and then manually assign a value to the record's field
or is there another way?


In most cases, you can set the control's DefaultValue
property instead of the Value property. The default value
will the show up a new record, but will not actually be set
until the user types a character in some other control,
c;icks a check box, selects an item in a list, etc.

Setting the DefaultValue property in VBA code can seem kind
of tricky if you are not familiar with how it is stored and
how it is used to set the Value on a new record. Here's the
different code for different data types:

' number type
Me.control.DefaultValue = number

' text type
Me.control.DefaultValue = """ & string & """"

.date type
Me.control.DefaultValue = Format(date, "\#yyyy-m-d\#")
 

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