10 April 2009

Calculated fields in Access forms

I'm having a little trouble with the Wholesale Price. I have a field for it on my order form (frmOrder). The label is named Wholesale Price. The next box to the right has the expression =[tblBook_RetailPrice]*0.8 . The Wholesale Price shows up fine on the form, but doesn't make it to the Order Table (the tblOrder_WholesalePrice field). I've attached a screen shot of the Design view of the order form. Once again I'd really appreciate any guidance you can give me.

The expression you have in your form shows you (but only in the form) the value that your expression creates. To get that created value to go into your order table via the form, you have two choices. The one I want you all to exercise for this task is the simple one listed below.

Simple approach - create a form with a wholesale price bound to the wholesale price field in your Orders table (the tblOrder_WholesalePrice field) so that any value you manually place in that field in your form will be placed into the bound field in the Orders table (the tblOrder_WholesalePrice field). If you wish to have a created value to see and to work with, you can add a text box control to your form and place the expression (=[tblBook_RetailPrice]*0.8) in it. This expression will read the value of the book that you have bound to the relevant book table field and calculate it's 80% value. You can then use that value to enter into the field bound to the Orders table (the tblOrder_WholesalePrice field). This is not very elegant, but it suffices for the purpose of this subtask.

More elegant approach - you can create a Visual Basic macro that is built into the OnClick subfunction for the field you wish to calculate. In simple terms, one can create a VB macro for the bound field that will accomplish the manual task I laid out in the simple approach. However, this requires going into Visual Basic and we don't have the time to do this in our class.

If one wishes to know more about it, one can look online at
http://office.microsoft.com/en-us/access/CH100621381033.aspx or one can use the book
Access Database Design & Programming, Third Edition. If one wishes to get more into Access, this book is a good one. But if one only needs an intro to relational databases, the simple approach is the one I would recommend.

0 comments: