David Ehrenreich said:
I have two list boxes that list door characteristics.
Then I have a total box. What I like to do is, depending
on what was selected the total will appear in it's feild.
So, for example: List1:3x7 was selected(Cost $10) then
List2:Oak wood(Cost $75) ---> total $85.
If anyone could help me with this that would be great. I
have little Vb skills, but learning.
You don't say what column of each list box contains the cost. Let's
suppose that it's the third column in each. In VBA, the third column of
a combo box is Column(2), because the columns are zero-based. So your
total text box might have a controlsource expression like this:
=Nz([List1].[Column](2), 0)+Nz([List2].[Column](2), 0)
I've used the Nz() function to ensure that Null values (for when nothing
is selected yet) are treated as zeros.
Note that this text box is a calculated control, and hence its value is
not stored in any actual table field. That would not be necessary or
desirable unless the prices are subject to change, because you don't
generally want to store any value that can be recalculated at any time.
However, since you're computing costs, it may well be that you *do* need
to store either the calculated value, or the individual costs of the
items selected in the list boxes. I'd recommend having fields in the
form's recordsource table to store the individual costs (e.g., SizeCost,
CompositionCost) and setting them directly in the list boxes'
AfterUpdate events; e.g.,
Private Sub lstSize_AfterUpdate()
Me.SizeCost = Me.lstSize.Column(2)
End Sub
Private Sub lstComposition_AfterUpdate()
Me.CompositionCost = Me.lstComposition.Column(2)
End Sub
Then you would have a calculated text box for totals that has this
controlsource expression:
=Nz(SizeCost, 0)+Nz(CompositionCost, 0)
Again, the total would not be stored, but can always be calculated in a
form, report, or query by repeating the expression.