Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling all experts! Is Null problem

Status
Not open for further replies.

sdimaggio

Technical User
Jan 23, 2002
138
0
0
US
I have a major problem.

I created a formula on a form in a Primary Key text box that relates to back to the form. When I go to save the data I get an error that reads:

"Primary Key can not contain a null value"

I do not have the field in the table set to required.

What I was attempting to do is on the close event when closing the form I was going to put the following code inorder to record the data back to the table.

[approval Number]= [approval number calc]

any suggestions?

I'm stumped.

Steve

 
The error message means exactly what it says. A record in a table cannot have Null as the value in the Primary key field for that table.

What is happening is that the events occur in a specific sequence that is making your "OnClose" code too late.

I am guessing that your user is in the middle of editing a record. Then, they click a "Close" button on your form. Your close button probably simply issues a docmd.close

What you are not aware of is that Access will actually fire a couple of events BEFORE it gets around to running the On Close event.

What happens is Access immediately fires the following:

Before Update
(Save the record)
After Update
On Current
On Close
On Unload

So, you need to put your code either in the "Close" button before doing docmd.close, or put it in the "Before Update" event.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top