Colin@Toyota
What's an Access?
- Local time
- Today, 07:29
- Joined
- May 2, 2006
- Messages
- 203
Colin, just one thing I think:
the program will most likely give you a "for" without "next" error when you run this.Code:Private Sub Form_BeforeUpdate(Cancel As Integer) Dim cntrl As Control strTimeStamp = Now() strUserID = Environ("UserName") If Me.Dirty = True Then For Each cntrl In Controls If cntrl.Value = cntrl.OldValue Then Next cntrl Else DoCmd.SetWarnings (False) Set rs = CurrentDb.OpenRecordset(Me.RecordSource, dbOpenDynaset) With rs .AddNew ![Exchange Rate] = Me.Exchange_Rate ![FOB] = Me.FOB ![Misc] = Me.Misc ![Freight] = Me.Freight ![TMC Royalty] = Me.TMC_Royalty ![Duty Rate] = Me.Duty_Rate ![Tooling Upfront] = Me.Tooling_Upfront ![Tooling] = Me.Tooling ![Volume Forecast] = Me.Volume_Forecast ![TCI Margin] = Me.TCI_Margin ![Dealer Margin] = Me.Dealer_Margin ![Timestamp] = strTimeStamp ![UserID] = strUserID .Update .Close End With Set rs = Nothing DoCmd.SetWarnings (True) Exit Sub End If [COLOR="Red"]NEXT CNTRL[/COLOR] End Sub
I'm missing an End If in there too...
I will also need to set the fields in the form back to the values stored in the variables somehow so that Access doesn't automatically save the changes because the form is dirty... Would it be best to call the variables back to each of the text boxes? or could I use me.undo to remove the changes (as long as that doesn't negate the above!)
Now when the user saved the changes if bFlag was True it would create the new rercord in the Audit table saving the strChangesMade variable to a description field. This let me know what had changed. In your example it creates the new record but does not give any indication as to what actually changed. Unless I missed a bit.
In my case there is another form that shows the part information, with a subform in datasheet view that will list all the associated records from the pricing table... in essence, the first record in the subform will be the original pricing info, and the last will be the most recent, allowing the user to see all the changes over time.
Last edited: