Mod Oper -- devil in the details

  • Thread starter Thread starter Tom McMillion
  • Start date Start date
T

Tom McMillion

I set up form bound to a simple table with 4 fields:

OrderQty
PalletQty
Splits
Remainder

All 4 fields in the table are Long Integer data type.

The Splits field is supposed to = [OrderQty]\[PalletQty]
Remainder is supposed to = [OrderQty]Mod[PalletQty]

I created a command button on the form to run a macro
which goes to control Splits, then executes the Run Code
command on the first line above; that is:

=[OrderQty] \ [PalletQty]

The macro then goes to control Remainder and executes the
following Run Code command:

=[OrderQty] Mod [PalletQty]

It's not working. The Splits field and the Remainder
field each have zero (0) in them. The cursor moves
though both fields but each of the fields stays at 0. No
error messge, just doesn't update the Splits and
Remainder field as I desire.

What am I missing? I looked up Mod Operator on Visual
Basic help and it says to establish a variable first. I'm
obviously leaving something out or else I need to create
a variable and the rest of the code in VBA somehow,
rather than trying to use existing commands in the macro
designer to do this.

I would really appreciate any help. Hope this is enough
of info. Thanks.
 
Remove the calculated fields from the table. Then create a query based on
the table (which now has 2 fields in it), and enter the calculations in two
new columns in the query. Use the query as the basis for your form, and get
rid of your code. (It's never a good idea to store calculated results in a
table, and it's also more work than doing it properly.)
 
Thanks so much for the help. Pardon my ignorance but
where do I create and insert each expression? Those are
two expressions, correct?

Thanks again.
-----Original Message-----
Me!Splits = [OrderQty] \ [PalletQty]
and
Me!Remainder = [OrderQty] Mod [PalletQty]

Of course you really should just use an expression to calculate these on-the-fly and
not store them in the table at all. No field in a table should ever be derived from
other fields. You have a computer capable of doing calculations. Use it.


.
 
Back
Top