I never use look up fields, MVFs or calculated fields.
One way would be to write a user defined function (UDF).
A function generally is used to return a value, where a sub does not.
You mentioned "Inches" and "mm" (we'll call them "Units"). In the function (lets call it "UnitCalcs")m you would have to have calculations for each "Unit" type.
You pass the unit type to the function and in the function have a Select Case construct to pick which calculation to do.
Code:
Function UnitCalcs (pUnitType as string) as Double
This says: there is a function named "UnitCalcs" that takes a string parameter and returns a number of type Double. (I use the prefix "p" for parameter - as in "pUnitType")
Then you have a Select Case:
Code:
Dim Result as Double
Select Case pUnitType
Case "Inches"
'do some calculations here
Result = 1 * 2
Case "mm"
' do some calculations here
Result = 3 * 4
Case Else
'in case something in not recongised
Result = -1111 'what I use to tell me an error occurred
End Select
Then you have to set the return value. You use the name of the function:
So the UDF looks like:
Code:
Function UnitCalcs (pUnitType as string) as Double
Dim Result as Double
Select Case pUnitType
Case "Inches"
'do some calculations here
Result = 1 * 2
Case "mm"
' do some calculations here
Result = 3 * 4
Case Else
'in case something in not recognized
Result = -1111 'what I use to tell me an error occurred
End Select
UnitCalcs = result
End Function
Obviously, there needs to be more to this function, but this is the general idea.
Now you can use this UDF from anyplace in the dB by passing a parameter that the UDF is expecting. The UDF would need to be able to get the required values for the calculations or you could pass the thick, length, width as parameters along with the units.
You could use the UDF in a text box:
Code:
=UnitCalcs("inches")
or in a query:
Code:
SELECT field1, field2, MyCals: UnitCalcs("mm")
FROM MyTable
You might also just do the calculation in a query, if the calculation is simple enough. If the thick, length, width were in the record, in a query you cluld use:
Code:
SELECT thick, length, width, Vol: thick * length * width
FROM MyTable
It really depends you what your requirements for the calculations are.
Does this help??