At this point you probably need to show us the exact code you've tried that doesn't work.
You also need to be aware that if any of your Controls are empty (i.e. Null) then adding them together will result in a Null!
If, for instance,
Me.X = 5
and
Me.Y = 10
then
Me.X + Me.Y = 15
But if
Me.X = 5
and
Me.Y is empty (Null)
then
Me.X + Me.Y will be Null (appear 'empty')
Depending on your exact code, this may be what is happening. To keep this from happening, you'd have to use the Nz() function. This function assigns a Value to a Control that is empty (Null). For instance, with
Nz(Me.Y, 0)
you're telling Access that if Me.Y is empty, or Null, then assign the Value of 0 (zero) to it. So, as said before, if
Me.X = 5
and
Me.Y is empty (Null)
then
Me.X + Me.Y will be Null (appear 'empty')
But if you used
Nz(Me.X, 0) + Nz(Me.Y, 0)
it would be processed as
5 + 0
and so
Nz(Me.X, 0) + Nz(Me.Y, 0) = 5
The 0 in
Nz(Me.X, 0)
could be replaced with any other appropriate Value. If, for instance, the Control named X could possibly be used as a divisor, using 0 (zero) wouldn't work. While most people would consider that dividing a number by nothing would be equal to that number, division by zero is illegal in VBA, and pops an error.
So, if
Me.A = 10
and
Me.B is empty (Null)
then
Me.A/Me.B will pop an error!
But
Me.A/Nz(Me.B,1) will, in fact, equal 10, because you're now dividing 10 by 1, which equals 10.
You can even assign a Text Value, if the Control is bound to a Text Field.
If you simply use
Nz(Me.ControlName)
without specifying a Value to insert, Access assigns a Value appropriate for the DataType of the Field that is Bound to ControlName.
Linq ;0)>
Last edited by June7; 02-22-2014 at 02:11 AM.
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007