going to try this again

E

Evil_jay

I have a form that has 1 Combo box (productid) 3 text boxes
(Quantity,UnitPrice,Price). I have to be able to select the product and have
my database autofill in the Amount of the product in the unitprice textbox
and it all has to still work with expression in my price Textbox
(Price=[Unitprice]*[Quantity])

I'm new to this can someone help me write the expression i need
 
B

BruceM

You have already asked something very similar, I think. My answer is
likewise similar to the one you received earlier, but maybe with different
wording it will be clearer.
Your combo box (I will call it cboProduct) has a row source. If you click
the three dots next to Row Source on the Data tab of the combo box property
sheet, you will see a query design grid. It is probably based on your
products table. I will assume that product description is in the first
column, and price in the second. Make sure the combo box column count is 2,
the column widths are 1";0 (or whatever you need instead of 1"), and the
bound column is 1. cboProduct is bound to the Product field. In my example
txtQuantity is bound to the Quantity field, and txtPrice to the Price field.
In the combo box After Update event:

Me.txtPrice = Me.cboProduct.Column(1)

In an unbound text box (txtTotal) put the following for the Record Source:
=Me.txtQuantity * Me.txtPrice

This is one way of doing what you need. The details and exact system would
depend on the structure of your database. I could assume that you have an
Orders table (tblOrders) and a Order Details (tblDetails) table, and that
there is a main form based on tblOrders and a subform based on tblDetails,
and that all of this will happen on the subform, but I won't go too far down
that road in the absence of details.
 
K

Ken Sheridan

Push the value in to the UnitPrice text box with code in the combo box's
AfterUpdate event procedure, e.g.

Me.UnitPrice = DLookup("UnitPrice", "Products", "ProductID = " & Me.ProductID)

Don't use an unbound control on the form for the UnitPrice; bind it to a
UnitPrice field in the table to which the form is bound. If you look up the
value on the fly each time then the values in old orders, invoices or
whatever the form is recording, will take on the new values as the UnitPrice
in the Products table changes rather than keeping the value at the time of
the order.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top