View Full Version : Calculations


bev
02-11-2002, 02:46 PM
Greenhorn here, need a little help with forms. I am creating a form for a customer who wants to have a quote form in which the unit cost of a product is retrieved, and a combobox will display a choice of 3 calculations (profit margin of 5%, 10%, and 15%) and they would have the ability to also type in a random amount.

I currently have a subform set to view as datasheet, with VB code in the combo box as below:

Option Compare Database

Function ListProfitMargin(fld As Control, id As Variant, _
row As Variant, col As Variant, code As Variant) _
As Variant
Dim margin
Select Case code
Case acLBInitialize ' Initialize.
ListProfitMargin = True
Case acLBOpen ' Open.
ListProfitMargin = Timer ' Unique ID.
Case acLBGetRowCount ' Get rows.
ListProfitMargin = 3
Case acLBGetColumnCount ' Get columns.
ListProfitMargin = 1
Case acLBGetColumnWidth ' Get column width.
ListProfitMargin = -1 ' Use default width.
Case acLBGetValue ' Get the data.
margin = " (" & ((row + 1) * 5) & "%)"
marginvalue = FormatCurrency([UnitCost] / (1 - ((row + 1) * 0.05)))
ListProfitMargin = marginvalue & margin
End Select
End Function

It works fine for the first record entered, but the calculated margin choices for each subsequent record do not reflect the unit price of the current product, but reflect the cost of the first product entered.

Any help or ideas would be greatly appreciated! Thank you

David R
02-11-2002, 02:54 PM
Requery your calculated fields when you move to a new record. Look up the Requery action in help, or in this forum.

HTH,
David R