PDA

View Full Version here: : Access


TrevorW
24-07-2012, 08:36 PM
:question::thanx:

I have an Access form created in 2007

a person enters an invoice total called invtot

the invoice total is then allocated against 4 cost codes called

A1,a2,a3,a4,

in the form footer I do a calculation tha adds the values of a1,a2 ... progressively after each amount is entered in a1,etc and this is totaled it a field named tota

before existing to a new record I need to check that tota agrees with invtot how do I validate this using VBA code and where would I place the code

:D

silv
24-07-2012, 09:01 PM
spacey :D

maybe this (http://www.access-programmers.co.uk/forums/showthread.php?t=198356)helps as to the basic structure and where to put the code?

regarding the code itself:
I always stole VBA code from Excel Macros:
Create a table and do with it what you described.
Once you're sure about the correct outcome, do it again in a new table while recording the actions into a macro.
The code of the macro can be viewed, afterwards.
You'd have to amend it to follow your form field names etc. But it could give you a rough guide.


Good Luck! ;)

TrevorW
25-07-2012, 05:10 PM
Actually worked out much simpler


Private Sub Form_AfterUpdate()
Me.Refresh

If Me.Invoice_Amount <> Me.INVTOT Then MsgBox "Totals don't agree."
Me.Amount1.SetFocus
End Sub