Update query

  • Thread starter Thread starter Google
  • Start date Start date
G

Google

I need for an update query to run as soon as an amount is
entered in a field like Start Reading , Ending Reading =
Amount Used I know how to make an update query but I
can't get the table to update a field on a form as soon
as I enter the Ending Reading. I have made a micro that
opens the update query when I hit he enter key on the
Ending Reading field and it will update the table but I
have to close the form and reopen it to make the amount
used field to reflect the change
Can some one help
 
You don't want a macro (or a micro :-)

Put code behind the form on the Ending Reading text box after update
that does one of two things:

If the field you want to update is on the form (or at least in the record
source behind the form) then simply set its value.

Private Sub EndingReading_AfterUpdate()
Me.AmountUsed = Me.EndingReading
End Sub

Otherwise, if the field is in another table, use an UPDATE SQL.

Private Sub EndingReading_AfterUpdate()
CurrentDb.Execute "UPDATE tblTwo SET [AmountUsed] = " & Me.EndingReading
End Sub

This UPDATE statement assumes the value is numeric. For text, it
must be surrounded by single quotes and for dates, the pound sign (#).
 
Back
Top