update query gone wrong

Puso

Registered User.
Local time
Today, 18:30
Joined
Sep 21, 2005
Messages
14
please help, i have a form where i enter goods recieved vouchers,in this form if the cost price on the form is higher than the price in the Stock table then the price must be updated, if the price is lower then the price in the stock table doesnt need to be updated.
I have a method which i have used before with no errors:
i run an if statement on my Lost Focus() event procedure on TxtCostPrice
it looks like this:

Sub txtCostPrice_LostFocus ()
Dim Cost1 As String
Dim Cost2 As String
Cost1 = txtCostPerUnit
Cost2 = DLookup("price", "Stock Numbers")

If Cost1 < Cost2 Then

Dim DocName As String
DocName = "updateIfCostPrice"
DoCmd OpenQuery DocName, A_NORMAL, A_EDIT

MsgBox "Cost price has been updated"

ElseIf Cost1 > Cost2 Then
MsgBox "Cost price does not need to be updated"

End If

End Sub
this code links me to my update query, everything on my update query looks fine but when i run the code it doesnt seem to be updating.

Please help as my deadline is fast approaching at an arlaming speed!
 
Hello Puso!

1) Is in your table only one sort of the goods?
Maybe in DLookup you need to add WHERE.......
2) I think if Cost1 < Cost2 need to bo if Cost1 > Cost2
 
the table is based on jewllery stock, all stock has unique identifyers via the product code.
how do you mean i must add a where clause in the dlookup?
 
Last edited:
I said maybe, it means if you have got more then one sort of goods,
it means that evry sort of goods has a diferent price.
How do you know which price "DLookup" catch.
 
MStef said:
I said maybe, it means if you have got more then one sort of goods,
it means that evry sort of goods has a diferent price.
How do you know which price "DLookup" catch.

In my update query it has a criteria clause which says:
[Stock Numbers]![Product Code] = [Forms]![Goods Receive Details Mainform]![Embedded40].[Form]![txtCode]
 
The query is still not updating, Now it gives me an error:
Records were not updated due to lock violations
 

Users who are viewing this thread

Back
Top Bottom