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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Primary Key Volilation - runtime 515

Status
Not open for further replies.

MikeMcKeown

Programmer
Apr 1, 2003
69
GB
Hi all,

I have created a front end in an Access adp project. I have forms for the input of information based on tables in SQL Server.

I have a problem if i select to enter a new record or move to another form and dont complete all fields including the primary key. So when I go to save I have an incomplete record:-

i get an error message saying that I am trying to insert a null primary key - which is correct. However there are some instances in the interface when I am just query the one field on the form to open another - so hence the primary key might be null.

Is there a way so when the user click to close the form or search when a record is not complete, prevent the error message appearing. To stop the database thinking that I am trying to enter a new record and hence prevent the error message from appearing. If there a cancel command??

Hope this makes sense and any help would be greatly recieved I have been trying this for a complete of days now.

Thanks in advance
 
Sorry for the spelling in the title!!!

I have been looking around a bit more and see that you can trap errors and specify what to do. I have entered the code taken for a post in to my Form OnError Event. This then throws up my error specified and then an Access Error asking if i want to save the record or return to the record. But there are a couple of things confusing me:-

1) This does not trap the error throughout the form and it still is displyed when I go to an Drop down search box when the new record I am entering does not contain the PK. i would have thought this would have been trapped. Is there a way to trap the error anytime it appears on the form?

2) Is there anyway to custom the Access message which is displayed. It does not have a number so I therefore assume that you cant do it?

If dataerr = 515 Then
MsgBox "You have entered a record which does not contains a PK therefore the record will not be saved this time"
response = acDataErrContinue ' telling Access not to show default message
End

Then the Access Message is displayed.

Thanks
 
Any table with a primary key must have a value for the primary key. Primary keys are, by definition, required fields.

Questions about posting. See faq183-874
 
I am not wanting to enter a null primary key. What is happening is a user might be entering a record and not complete all fields including the PK.

I then get the 515 error message. I would like an error message to be displayed to the user saying that they have entered a null null primary key. This would give them the option to cancel the current new record entry.

However I am not sure how to cancel a record entry. As if the user changes their mind about the current record it does not let you even delete it as 515 keeps on coming up until you enter a PK.
 
Of course you can't delete it the record has not been saved. The only thing you can do is cancel it. As to how to do that, an Access forum is probably a better place for this question as you will have to do that in vba. Try forum705.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top