Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

How update field in separate table when value in form changes

I have a form which has tblPartsMasters as its record source.  When the vale in one of the fields on the form changes I want that value written to a field in a separate table.  Basically this is what I'm trying to accomplish.  I need help figuring out what the after update event of the field on the form should be...

On afterupdate event of field “txtPatt_Loc” (control source is [Patt_Loc] in “tblPartsMasters”) on “frmJobCards” update
The field [Patt_Loc] in “tblOpenOrders”
Where
[Part_No] = “txtPartN” on “frmJobCards”

--Steve
Avatar of mbizup
mbizup
Flag of Kazakhstan image

In the After Update event:

DIM strSQL as String
strSQL =  "UPDATE tblOpenOrders SET [Patt_Loc] = " & chr(34) & Me.txtPatt_Loc & chr (34) & " WHERE [Part_No] = " & chr(34) Me.txtPartN & chr(34)
CurrentDB.Execute strSQL, dbFailOnError

Open in new window


I'm assuming that both Patt_Loc and Part_No are text.  If either is numeric, drop the surrounding chr(34)'s
Avatar of SteveL13

ASKER

Yes, both fields are text.  But as usual, I forgot to mention one thing.  I am sorry.  When the update happens it needs to update all records in the tblOpenOrders where the Part_No is the same AND a Yes/No field named "Complete" is false.

Can you help a little more?
Just add it on to the WHERE clause:


DIM strSQL as String
strSQL =  "UPDATE tblOpenOrders SET [Patt_Loc] = " & chr(34) & Me.txtPatt_Loc & chr (34) & " WHERE [Part_No] = " & chr(34) Me.txtPartN & chr(34) & " AND Complete = 0 "
CurrentDB.Execute strSQL, dbFailOnError

Open in new window



Alternatively:

DIM strSQL as String
strSQL =  "UPDATE tblOpenOrders SET [Patt_Loc] = " & chr(34) & Me.txtPatt_Loc & chr (34) & " WHERE [Part_No] = " & chr(34) Me.txtPartN & chr(34) & " AND Complete = FALSE "
CurrentDB.Execute strSQL, dbFailOnError

Open in new window

When I copy/paste this line...

strSQL =  "UPDATE tblOpenOrders SET [Patt_Loc] = " & chr(34) & Me.txtPatt_Loc & chr (34) & " WHERE [Part_No] = " & chr(34) Me.txtPartN & chr(34) & " AND Complete = FALSE "

it turns red.

??
A message pops up...
Compile Error: Expected: End of statement
It should all be on one line...
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan 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
Perfect.  Thanks!
:)

Glad to help