Having problems with the behaviour of this code:
Dim lngMaxRec As Long
'find max record number in series lower then current value, assign 0 if none exists
lngMaxRec = Nz(DMax("[OdoNum]", "tblOdo", "[RecNum] = " & Me![RecNum] & " AND [OdoNum] < " & Me![OdoNum]), 0)
'assign current ending (defualt value)
Me![EndOdo] = Me![BegOdo]
If Not (lngMaxRec = 0) Then
'if not the first record in series
DoCmd.SetWarnings (False)
DoCmd.RunSQL ("UPDATE tblOdo SET EndOdo = " Me![BegOdo] & " WHERE OdoNum = " & lngMaxRec & "")
MsgBox "UPDATE tblOdo SET EndOdo = " Me![BegOdo] & " WHERE OdoNum = " & lngMaxRec & ""
DoCmd.SetWarnings (True)
End If
It will work fine, on the first record in the subform.. it will work fine, for the 2nd, 3rd.. etc.. problem is, say i enter a whole bunch of values in another field in the table (state codes) before i start punching in the odometer readings.. then, i go back and update the BegOdo field
the msgbox pops up, as it should, cept, the query never runs.. the message box values are right on the mark, which is giving the probs. If the message box is giving the same values the update query uses, should the update query not work????? it should in my opinion.. but doesn't for some reason
the code is in the 'afterupdate' event of my BegOdo field..
P.s. I know i'm breaking the rules of Norm, it was my only solution.. so please, no comments on why i'm storing a field value in 2 records.
Thanks in advance for anything you can offer!
Yours Truly,