T
TeeSee
The following code runs and the variables contain the desired data but
the underlying table doesn't get updated. Can anyone see the error of
my ways? There are no error messages with this code. It just does
nothing!
This has been adapted from Graham Mandenos' post of some years ago
which was run under the Form_BeforeUpdate as you can see. Can this
type of code also be run from the text box control BeforeUpdate as
well since I am only capturing a single field?
Thanks as always
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim CtlSource As Variant, Ctl As Control, intCtl As Integer
Dim db As DAO.Database, rsMMhist As DAO.Recordset
On Error GoTo Form_BeforeUpdate_Err
Set db = CurrentDb()
Set rsMMhist = db.OpenRecordset("tblMaterialMasterHistory")
CtlSource = Ctl.ControlSource
If ListPrice = ListPrice.OldValue Then
'do nothing (Still working on it)
Else
'field has been changed - add record to history
Debug.Print "TestPosition"
rsMMhist.AddNew
rsMMhist!Originator = CurrentUser()
rsMMhist!ChngeDate = Now()
rsMMhist!oldlistprice = ListPrice.OldValue
rsMMhist!newListPrice = ListPrice.Value
rsMMhist!ControlSource = CtlSource
Debug.Print ListPrice.OldValue ' ********* correct value
here ********
rsMMhist.Update
End If
Form_BeforeUpdate_Exit:
On Error Resume Next
rsMMhist.Close
Exit Sub
Form_BeforeUpdate_Err:
If Err = 2455 Then
MsgBox Error$
Cancel = True
Resume Form_BeforeUpdate_Exit
End If
End Sub
the underlying table doesn't get updated. Can anyone see the error of
my ways? There are no error messages with this code. It just does
nothing!
This has been adapted from Graham Mandenos' post of some years ago
which was run under the Form_BeforeUpdate as you can see. Can this
type of code also be run from the text box control BeforeUpdate as
well since I am only capturing a single field?
Thanks as always
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim CtlSource As Variant, Ctl As Control, intCtl As Integer
Dim db As DAO.Database, rsMMhist As DAO.Recordset
On Error GoTo Form_BeforeUpdate_Err
Set db = CurrentDb()
Set rsMMhist = db.OpenRecordset("tblMaterialMasterHistory")
CtlSource = Ctl.ControlSource
If ListPrice = ListPrice.OldValue Then
'do nothing (Still working on it)
Else
'field has been changed - add record to history
Debug.Print "TestPosition"
rsMMhist.AddNew
rsMMhist!Originator = CurrentUser()
rsMMhist!ChngeDate = Now()
rsMMhist!oldlistprice = ListPrice.OldValue
rsMMhist!newListPrice = ListPrice.Value
rsMMhist!ControlSource = CtlSource
Debug.Print ListPrice.OldValue ' ********* correct value
here ********
rsMMhist.Update
End If
Form_BeforeUpdate_Exit:
On Error Resume Next
rsMMhist.Close
Exit Sub
Form_BeforeUpdate_Err:
If Err = 2455 Then
MsgBox Error$
Cancel = True
Resume Form_BeforeUpdate_Exit
End If
End Sub