Write Conflict (1 Viewer)

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
Hi all,

Please could you assist?
I select a product from a drop down list, after update it should lookup a value from the same table and update my current table
for some reason it is not doing the update but when I manually click on the update query, I get the write conflict error

My code behind the after update is:
Private Sub Product_AfterUpdate()

DoCmd.SetWarnings False
DoCmd.Save
DoCmd.GoToControl "Qty"
DoCmd.OpenQuery "Update Purchase Request - UOM"
DoCmd.SetWarnings True
End Sub

Below is my update query
UPDATE [Transactions - Procurement - Temp] INNER JOIN Products ON [Transactions - Procurement - Temp].Product = Products.[Short Description] SET [Transactions - Procurement - Temp].UOM = [Products]![UOM]
WHERE ((([Transactions - Procurement - Temp].Product)=[Forms]![Purchase Request]![Product]));
 

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
Its likely that the conflict is that you are trying to write to a bound control on a form.
See my article Write Conflict Errors (isladogs.co.uk) for other possible causes & solutions
The UOM control is a blank field on the temporary file I am updating
Also not sure why the update query does not run after update and only updates when I do a manual click on the query, and then the write conflict
I thought that saving after the update before the query runs would help but it has no effect
I can not really give it a default value
 

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
I added zero as a default, the query still does not update but I dont get the write conflict error

When removing the update query when selecting the product and added to after update on the Qty, it works fine, even with no default value in the UOM control
 

Minty

AWF VIP
Local time
Today, 11:31
Joined
Jul 26, 2013
Messages
10,371
If the value you are looking up could be brought into the combo you could simply set the other field to that combo column's value, and not need the update query at all.

Also DoCmd.Save in a form has nothing to do with saving the record, but saves any changes to the form design.
 

ebs17

Well-known member
Local time
Today, 12:31
Joined
Feb 7, 2020
Messages
1,946
for some reason it is not doing the update
DoCmd.SetWarnings False ... if you close your eyes, you can't see anything that's happening. But experience.

DoCmd.Save ... would save changes to the form definition made via design view. This is different than saving a record that has just been edited.
It is therefore possible that the data record is still being edited and is therefore locked. It's helpful to avoid doing much of this DoCmd stuff.
Code:
If.Me.Dirty then Me.Dirty = False
 

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
If the value you are looking up could be brought into the combo you could simply set the other field to that combo column's value, and not need the update query at all.

Also DoCmd.Save in a form has nothing to do with saving the record, but saves any changes to the form design.
Assuming I add the UOM to the part number dropdown box, how to I get the information of the second column from the drop down box to the UOM control?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:31
Joined
May 7, 2009
Messages
19,243
I select a product from a drop down list, after update it should lookup a value from the same table and update my current table
that is the Problem. Don't you see.
You have same Record (on same table) that is being edited, yet you are Updating it through SQL.
that is definitely a No, no.

include the UOM field in the form and update it on the form.
 

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
that is the Problem. Don't you see.
You have same Record (on same table) that is being edited, yet you are Updating it through SQL.
that is definitely a No, no.

include the UOM field in the form and update it on the form.
Hi,

That is what I am doing, once I have selected the product, the UOM should be updated via a query but then I get the write conflict error even though i am not updating the UOM control

If I can include the UOM in the product dropdown box, how do I link the unbound control to the second value in my dropdown box?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:31
Joined
May 7, 2009
Messages
19,243
are you Updating Same table that is in the Form?
if you are that is a Write Conflict, since your Form is Dirty but it "sense"
that you already updated it, before the record in the Form got saved.
 

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
are you Updating Same table that is in the Form?
if you are that is a Write Conflict, since your Form is Dirty but it "sense"
that you already updated it, before the record in the Form got saved.
Yes I am updating the same table that is in the form
 

Minty

AWF VIP
Local time
Today, 11:31
Joined
Jul 26, 2013
Messages
10,371
Assuming I add the UOM to the part number dropdown box, how to I get the information of the second column from the drop down box to the UOM control?
Simple - but firstly do you need to actually store it or simply display it?
If it's in the Product table anyway you probably shouldn't be storing it.

To display it in an unbound text box use something like

=CboProducts.Column(2)

Assuming the UOM is the third column in the combo rowsource.

If you need it stored then in the after-update event

Me.YourUOMControl = Me.CboProducts.Column(2)
 

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
Simple - but firstly do you need to actually store it or simply display it?
If it's in the Product table anyway you probably shouldn't be storing it.

To display it in an unbound text box use something like

=CboProducts.Column(2)

Assuming the UOM is the third column in the combo rowsource.

If you need it stored then in the after-update event

Me.YourUOMControl = Me.CboProducts.Column(2)
Than you, works awesome

Is there a way to link an exchange from the web into access?
 

Minty

AWF VIP
Local time
Today, 11:31
Joined
Jul 26, 2013
Messages
10,371
Than you, works awesome

Is there a way to link an exchange from the web into access?

I'm not sure what you mean?
Do you mean a web page update to access?
 

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
I'm not sure what you mean?
Do you mean a web page update to access?
My purchase order form has Vendors from around the globe, if i select a vendor which is not my country, I want to be able to add the exchange rate of that day to the order to calculate the correct total cost
If this could be done automatically this would be great instead of having to look up on the web and then enter the exchange rate
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:31
Joined
May 7, 2009
Messages
19,243
there is an Access exchange rate in sample database.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:31
Joined
May 7, 2009
Messages
19,243
you "Search the Forum".
 

Gismo

Registered User.
Local time
Today, 13:31
Joined
Jun 12, 2017
Messages
1,298
you "Search the Forum".
I found the currency exchange sample DB
Will have a look at it in depth but I dont see a from currency to To currency and the exchange
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:31
Joined
Feb 19, 2002
Messages
43,275
NEVER, run an update query that will update the current record.
ALWAYS save the current record before opening a different form or report or running any query.
 

Users who are viewing this thread

Top Bottom