Link to home
Start Free TrialLog in
Avatar of SowleMan
SowleManFlag for United States of America

asked on

How to solve runtime error '2147352567(80020009)'

I get this error when I try to change a control on a form and the control is a primary key in the underlying table.
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

If the PK is an Access AutoNumber (?), then it cannot be changed.

mx
Avatar of SowleMan

ASKER

Thanks, DatabaseMX.  

I really don't want to change the key.  I want to replace the key with another, valid PK.  For example, I want to modify a transaction record so it points to The Home Depot, instead of  Lowes.

Sowleman
Then something seems awry in your design...

For example: If you are a shipper and you want to change the ship destination from Home Depot, to Lowes.

The you have a "Stores" table:

tblStores
StoreID (Primary Key)
StoreName
...ect

..Then you have a shipments table

tblShipments
ShipmentID (Primary Key)
StoreID (Foreign Key)
ShipmentDate
...etc

These two tables are linked in the relationships window on "StoreID", and Referential Integrity is enforced.

In this case, it is quite easy to change the StoreID in the shipments table to another StoreID, without issue.

So you will have to explain to us the design and relationships between your tables.
Also provide us with the details of how and where, exactly, you are trying to change the ID.


JeffCoachman

Guess I'm not quite following.  Maybe Jeff has explained what you are after?

mx
Changing a value in a key field might result in a violation of normalization.  We need more information on what you are trying to do, in terms of tables, fields and relationships.
Thanks - I really appreciate your interest in my problem.
Jeff described my situation well.  I have a tblStores with fields StoreID (primaryKey, auto-number) and StoreName.  tblShipments contains a foreign key (also called StoreID) in order to retrieve StoreName via an ACCESS relationship.  I expect the relationship to maintain referential integrity.

In my system, I use a query to retrieve fields  from tblStores and tblShipments, and that query is the recordsource for my form. I sometimes detect an improper StoreName. Example: a tblShipments record shows Home Depot and I want to change it to Lowes.  Using VBA, I retrieve from tblStores the Lowes StoreID and I want to assign the Lowes StoreID to tblShipments.StoreID.  ACCESS replies with runtime error  '-2147352567(80020009)', "To make changes to this field, you must first save the record".

The actual VBA that causes the error: me.StoreID = longStoreID.  I am trying to make this change by assigning the correct StoreID to the foreign key (displayed but not enabled) in the form.

I am learning this stuff as a retirement hobby, so my education is weak in many areas.  30 years ago I programmed in COBOL.

Steve
Helen/ MX/ Jeff -  Could it be that I have to delete the inaccurate record and then add a new, correct record?  If am comfortable with DAO, but is there a way to manipulate the data in the underlying query without messing up the flow of the form?

Steve
Unless you also assigned StoreID in the shipments table as Primary key, I can't see what the problem might be...

You did not say by what method you are assigning longStoreID, but in a global sense you may want to use a combobox.

Here is a very simple sample, there are no problems with changing the store.

JeffCoachman


db344.mdb
ooops, ...here is the sample
db344.mdb
ASKER CERTIFIED SOLUTION
Avatar of SowleMan
SowleMan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did not get a workable answer.  I want to close it so I casn move on