How to display a value based on a different value in a different table in an MS Access form? - ms-access

I am a complete beginner. I am working on an invoicing project. Essentially, I have a table (tblCustomers) that stores a value (SalesType). The SalesType can be one of these values: Cash Sale or Trade Sale.
In another table (tblProducts), I have a list of products and their price. The prices are either a cash price or trade price. ProductType,CashPrice & TradePrice.
At the moment, on my invoice form (frmInvoice), I have 3 items. A combo box where user can select the product, a text box that displays the Cash Price and another text box that displays the Trade Price.
What I am looking for is a way for Access to check the SalesType from tblCustomer for a given customer and depending on what is listed there, i.e. either cash sale or trade sale, for a text box to display the correct price.

Read this article to use DLookup() function. It will solve your problem.
DLookup Function

Related

Create product form that allows selection of any item with MS Access

The following is a simplified version of my problem:
We have a product table containing all items available in a store. The customer should always see all products available for purchase. The items the user selects should be associated with his invoice record. I have modeled the relationship as follows:
tbl_Product <-1---m-> tbl_ProductInvoice <-m----1-> tbl_Invoice
How can I create a form that opens up to all products being available for selection. The solution "must" allow the customer to use a checkbox per product to make the selection. Listboxes are not allowed.
My solution to this problem is to have a bound invoice form with an bound product subform. When a new invoice is created, all possible product combinations are created, with the checkbox being set to false, so that the subform shows the products. What would be a more efficient way of doing this?

How to change a field on a sub-form depending on a value of a record

I have a product table with 2 different price for each product. In customer table I have a price category for each customer. When I open the order form, I choose the customer from a drop down list and the field of pricecategory show the type that the current customer has (1 or 2).
I tried to transfer the value of pricecategory to sub-form but I can't handle how to change the control source of the price field. Probably this approach doesn't work. How can I complete this task? I need the logic structure.
I tried with IIf statement in the control source with no success.
iif([forms]![Orders]![PriceCategory]=1,[Price1], iff([forms]![Orders]![PriceCategory]=2,[Price2]))
I try to find a way to change the control source from price1 to price2 in the field of a sub-form. Actually I want to automatically change the price field depending on the customer.
Thanks

MS Access: Add Const Value to Table from Different Table

I am building a simple invoice form in MS Access and have two tables that I am trying to link data across. One is a product table, which includes the price field. However, because the price can change at any point, I want to store the price at the time of sale in my line_item table as a constant, unchanging value.
Furthermore, I want to be able to lock both of the values in the invoice form so neither is able to be changed. Because of this, I don't want my sale_price entry in the line_item table to be manually entered. I want it to pull from the product table's price entry.
However, I have yet to find any documentation to help me achieve this exact result.
Can anyone help me out?
This is a common requirement.
Set textbox properties Enabled No and Locked Yes and TabStop No.
To retrieve the price it can be included as a column of combobox where product is selected.
Save the price into record with code behind the combobox AfterUpdate event. It can be done with a macro but I use VBA, ex:
Me!sale_price = Me.cbxProduct.Column(x) - for x reference the column index with the price, index begins with 0.

MS Access - Customized Price List

In MS Access, I've got Table A that lists products with the price for each product and Table B with Customer Name, Customer ID and the Profit Margin associated for each customer.
What I need to do is create a customized price list for each customer based on their profit margin. Each customer will receive the exact same list of products from Table A. The only difference being that the price column in Table A will change depending on the Profit Margin column contained in Table B.
Ultimately, I would use this to create a report that would then be emailed out to each customer.
I’m having some difficulty figuring out how to set it up so that all customers in Table A are linked to one price list with differing prices depending on their profit margin.
If anyone could help give me a push in the right direction I would greatly appreciate it.
Thank you
I'm assuming you have the following tables:
tblProducts, with fields Product and Cost.
tblCustomers, with fields Customer and Margin.
I'm not sure how your margin works (is it a factor which is multiplied by the cost, or a fixed amount which is added on?), but the formula should be easy to work out to suit your needs.
Create a query. In query design mode, show the two tables. Add the field tblProducts.Product to your query, and the expression [tblProducts].[Cost] * [tblCustomers].[Margin].
In the Criteria for this expression, you can set, for example, [tblCustomers].[Customer] = "John". Or, instead of specifying a particular customer, you could reference a control on a form. In this way, changing the control on the form (eg. selecting a customer from a listbox) will change which customer's data the query is based on.
Then you can build a query on the report as usual.

I haven't found an answer to suit my needs yet. How do I populate multiple tables using a single form?

I have a main table that is populated by a single form. This table has all of my customer info and lists all of the products we sell with the amount sold of each product to each customer. I am creating seperate tables for each individual product. I would like to know how to make this single form populate a row in the table for each individual product if the amount sold to a single customer is at least 1.
For example, say I'm selling widget_1, widget_2, and widget_3. On my main table, the customer info will be populated no matter what. Now, I have one table for widget_1,one table for widget_2, and one table for widget_3. If a customer orders only a #1 and a #3, I want their info to be input into the tables for widget_1 and widget_3, but not widget_2.
How would I do this?
Is there any reason why you cannot have a subform for widgets 1 to 3, if only a limited number of widgets are available? The main form does not have to be bound, the link master fields can be set to controls matched to the relevant subform fields, so that the data is automatically populated to the widget table when a quantity is entered into the relevant subform.