After Update doesn't

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I have a form which is used to track receipt of packages.
When the user updates the Date_Received field on the form,
a record is written to another table using the code shown
below. I have also written code so that when the user
double-clicks on the field, today's date is entered (which
is simply Me!Date_Received = Date). My problem is that if
the user enters the date manually, the update code works,
but it doesn't if they double-click. Any ideas why?

Private Sub Date_Received_AfterUpdate()

Dim CurrDB As Database
Dim CurrTab As Recordset

Set CurrDB = CurrentDb
Set CurrTab = CurrDB.OpenRecordset("tbl_History")

With CurrTab
.AddNew
CurrTab!Case_ID = Me!Case_ID
CurrTab!Status = 2
CurrTab.Update
End With

Set CurrDB = Nothing
Set CurrTab = Nothing

End Sub
 
A control's AfterUpdate event is not triggered when it's
contents are changed using VB or a macro.

You should consider moving your code to the form's
AfterUpdate eventhandler which will be triggered. You can
enclose your code in an If statement that checks the
oldValue against the current value to determine whether the
control has been changed e.g.

If Date_Received.OldValue <> Date_Received.Value Then
code to add the record to the History table
End If

There is another benfit in coding this way and that is that
you will only get one row added to the history table per
row change. As your coding stands, you would get two rows
added if the user made a mistake in the date then corrected
it before moving to another row.

Hope This Helps
Gerald Stanley MCSD
 
Tim said:
I have a form which is used to track receipt of packages.
When the user updates the Date_Received field on the form,
a record is written to another table using the code shown
below. I have also written code so that when the user
double-clicks on the field, today's date is entered (which
is simply Me!Date_Received = Date). My problem is that if
the user enters the date manually, the update code works,
but it doesn't if they double-click. Any ideas why?
[snip the working procedure]


If the DoubleClick event is changing the field and you want
to run the AfterUpdate event procedure, just call it. The
DoubleClick event can use a line of code to run the
AfterUpdate procedure:

Date_Received_AfterUpdate
 
Back
Top