View Full Version : For Loops


Charles111
08-27-2008, 11:45 PM
Hi Everyone,

This seems like a very simple problem but I've been stuck on this for quite some time but the situation goes as follows:

I have a continuous form with the following fields [margin], [amount] and [total]. I would like to be able to create a button "calculate" which will do the following: me.[total].value = [margin]*[amount] for all records where [total] = null.

Any help with be greatly appreciated!

Thanks

namliam
08-28-2008, 12:04 AM
You really should not store calculated values into your database.

Instead replace your Total field by an unbound control and put your formula in as its control source.
This will
1) Make your design better
2) Elimate yout button
3) Make your design better


Good Luck!

Charles111
08-28-2008, 02:36 AM
Thanks for the advice namlian, however, the purpose of storing calculated values is so I can manually change the values later.

KenHigg
08-28-2008, 02:42 AM
I would simply build an independant update query and execute it.

Charles111
08-28-2008, 02:49 AM
Nice thinking - I think that is the easier solution. However, just for the sake of asking, how would one go about doing it in VB? I've always been interested in writing loops but never could get my head them - any suggestions of examples or readings to go to?

KenHigg
08-28-2008, 03:21 AM
Hum... If you wanted to make the change for a single record I would do something like what you did. However if you wanted to rip through all of the records making the change carte blanche I think I'd use an update query. However if you wanted the ultimate control of what and how a record was was changed as you examine all of the records in a particular set then I'd recommend using recordsets. You can do a search on that topic to get started and if you need help post back - :)

Charles111
08-28-2008, 03:25 AM
Thanks Ken !

KenHigg
08-28-2008, 03:26 AM
Glad to help - :)