Re: Auto update fields



Thanks John that worked a treat. I am currently building a database for my
local sports Association to handle bar and canteen inventries, and event
nominations. I enjoy a challenge and learning access from scratch, is
certainly challenging! So no doubt I will be in touch against from time to
time in the next month.
Once a gain. Thank you very much for the speedy reply and useful advice.
--
binny


"John W. Vinson" wrote:

On Tue, 1 Apr 2008 19:52:04 -0700, binny <binny@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

Can someone please tell me how to have the priced field automatically show
the preset price of a product. When I enter an order into my form. I don't
want to have to manually enter in the price of the product. Every time I
select a product from a drop-down list. I know this can be done, because
there is an ex-ample of it in the templates. I don't seem to be able to ask
the right question, from help to get the answer I need. In short, I don't
know what I don't know. I'm sure this solution is quite simple, but I just
can't seem to find it.

It's actually a bit tricky, and requires a line or two of VBA code.

Include the price as one of the fields in the combo box's RowSource query. The
field need not be visible - you can set the ColumnWidths property of the combo
to conceal it by setting the width of that column to 0.

In the combo's AfterUpdate event you can then "push" the price from the combo
box into the bound textbox. Let's say the combo is cboProduct based on a query

SELECT ProductID, ProductName, UnitPrice FROM Products ORDER BY ProductName;

ColumnCount would be 3, Bound Column 1 (to store the ID), and ColumnWidths
something like

0";1.5";0"

so that the user sees only the product name.

In the AfterUpdate event property of the combo click the ... icon and choose
Code Builder. Access will give you the Sub and End Sub lines - edit it to:

Private Sub cboProduct_AfterUpdate()
If Not IsNull(Me!cboProduct) Then ' did the user select a product?
Me!txtPrice = Me!cboProduct.Column(2) ' zero based, (2) is the 3rd field
End If
End Sub

--

John W. Vinson [MVP]

.



Relevant Pages

  • Re: Auto update fields
    ... want to have to manually enter in the price of the product. ... box into the bound textbox. ... ColumnCount would be 3, Bound Column 1, and ColumnWidths ... Access will give you the Sub and End Sub lines - edit it to: ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Price Check: Firepower Pin
    ... John P. Dayhuff ... It is just really hard to get a decent price the ... I see a lot of games that sound ... Price is considerably than the value of the pinball machine to ...
    (rec.games.pinball)
  • Re: Need a lawyer pin sale
    ... has to pay the price  I dont think its anyone's ...  And dont bother asking me because I wont tell you either. ... fun with some old DE games or mabey an old jap bike. ... John saved me hours, by helping ...
    (rec.games.pinball)
  • Re: Amateur question pools and answers...
    ... There is no "price of admission" which needs be paid, ... > John, no one has ever been "forced" to learn CW to become a ham. ... and many of the hams on here could in short ...
    (rec.radio.amateur.antenna)
  • Re: Just Ordered The Sony 7600GR
    ... > Joe Analssandrini wrote: ... At a price of $200.00 they were ... Hi John and guys ... commodity "technically" speaking. ...
    (rec.radio.shortwave)