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!

Form and subform will not allow edits

Status
Not open for further replies.

cschmid

Technical User
Apr 1, 2002
8
0
0
US
I have a form and subform that will not allow edits and I receive and error that it will create duplicate values in the PK when I try and edit any information. This happens right before I tab into the subform and have made changes to fields on the main form. I have the properties set to yes for Data entry, Allow Deletions, Allow edits and RecordSet type set to Dynaset. Any assistance is appreciated.
 
Check the OnCurrent event of your subform to see if you are modifying the New record that is bound to the subform in any way. For example, you might be filling certain fields with required values before letting the user complete the data entry. Access processes subform events before main form events, and when you change data in a New record before filling in the Primary Key fields, you'll get errors related to duplicate keys. So, try moving any field initialization code from the OnCurrent event to the BeforeInsert event in you subform (and your main form as well).
 
From your description, the problem I suspect has to do with the definitions of the tables, and some of the form properties. I dont think has anything to do with the subform events Anyway, try the following:

(a) Set DataEntry to false. This will allow the form to expose ALL of its underlying records; not just new ones. Perhaps you are trying to add a new record without realising that it has been added before, because of the setting of this property.

(b) Check out the table definition of the table bound to the main form. Identify which field is the Primary Key, and confirm that this is the field that you indeed want to be unique in the table.

(c) Problems with the code are most likely to be in the OnCurrent or BeforeUpdate events of the main form and will cause your problem if the value associated with the PrimaryKey is incorrectly autogenerated (to be non unique) by this code. When you move from the main form to the subform, the BeforeUpdate associated with the main form is triggered and the main form's underlying record is saved, as you move off the main form into the subform. This is the point that your program is complaining.

(d) Another angle; try saving the main form record without moving into the subform (eg. display the main form record selector bar, and click to save when you have entered your data). If the problem occurs, then you've eliminated the subform as a candidate problem.
Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Wow...thanks for all the suggestions. I will try these and see what happens. Appreciate the help.
 
I am still having the same issue mentioned before:

I have a form and subform that will not allow edits and I receive and error that it will create duplicate values in the PK when I try and edit any information. This happens right before I tab into the subform and have made changes to fields on the main form. I have the properties set to yes for Data entry, Allow Deletions, Allow edits and RecordSet type set to Dynaset.
The main form is giving the error when I attempt to save the record even before I get into the subform. I have two tables (1 for the main form and 1 for the subform) and the subform is connected via the Primary key of the main form. Is their a certain code I need to use in order to edit the data? I have ttried allow edits but it still does not work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top