views:

51

answers:

1

Sorry if this is a newbie question, I'm a bit rusty in Access and even more rusty in Visual Basic!

I'm trying to find a way of changing a field in a table when a field in another (unrelated) form is changed. More specifically, I'm after a way of reducing the number in the table by whatever the value is in the form field (in a stock control way)

Does anybody know the best way to go about doing this?

A: 

The best way is probably an update query run via VBA, for example:

Dim db As Database
Dim strSQL as String

Set db=CurrentDB

strSQL="UPDATE Stock SET InStock=Instock-" & Me.OrderQty & " WHERE ID=" & Me.ID

db.Execute strSQL, dbFailOnError

MsgBox "Updated " & db.RecordsAffected & " record(s)"
Remou
That's fantastic, thanksMost of it works a treat except for one small problemI've changed OrderQty to be the name of the textbox, but I'm finding it's set as the old value inside the textbox (for example if it was 2 and I changed it to 3, 3 would be returned)Google isn't being much help here sadly :(
mlok1
mlok1