MS Access - Customized Price List - ms-access

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.

Related

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

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

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

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.

Update single records in query with form based textbox

I am working with Access2013 and I have a query called PaidOrderQ with columns "SalesRep", "Customer" and "PaidAmount". I need to calculate the SalesRep's commission which isn't always the same percentage for each record. After reading through similar questions here I still haven't figured it out yet.
The way I thought doing it is to have a form called PaidOrderF with soucre is PaidOrderQ, a textbox called "CommRate" and a calculated field "Commission". The "Commission" gets calculated by "AmountPaid"*"CommRate".
I'm not sure how the percentage for commission is calculated, but there are a few ways this can be done depending on how the percentage is calculated. The first would be if you can calculate the percentage that will be used automatically. Then you can add everything automatically (even if the percentage changes based on the item). If this is possible you can open the query up in DESIGN view. Then click onto a blank field and you can make a calculated field for example:
Commission: [AmountPaid]*[CommRate]
Now you can add the calculation for CommRate for example:
CommRate: IIf([AmountPaid]>200,.15,.2)
Which would make any the comm rate 15% over $200 and 20% under.
If not you can make Text boxes in a form (which would be unbound and add an after update vba code to multiply them together and change the value of a third text box, label etc.)
You may also want to add a column to the original table to show commission rate so the information would be stored for future reference.
Let me know if anything is unclear or you would like to see an example of the vba code
EDIT::
Storing information to a table:
This one will be very basic and you probably know most of this, but just in case I will include it because it is the most straight forward.
Add a column to the table you are working from by opening up the table in Design view (you can also make a temporary table by using a make table query if you are using a liked table or do not want to modify the structure, but it is better to put it in the main table if possible). Here you could make a query that includes all of the fields plus the additional calculated field that shows amount paid * commission. Then when you make a form based on the query you will enter in the commission rate and the form will both save the information and automatically update the field to give commission.
Linking another table by Primary ID -
If neither of those options work you could also create another table that shares a primary ID. This option will be more complicated, but is possible. (I would recommend not making it a true primary ID for the second table so it is easier to modify (Or have a true primary ID and the ID you will use to link ie. 3 total columns)). If this is the option you need I can go into more depth, but the disadvantage of this method is if there is no CommRate listed for a given record it will automatically hide the information (it is possible to avoid this, but again will be more complicated) so it will be easy to make a mistake.
VBA coding
VBA will be the most complicated solution, and has the largest disadvantages. First - You will have to loop all of the records at one time (or at least for one employee) and when you close the form you will lose everything. If there is any way to avoid this I would suggest doing so, but you could theoretically store the information in an array.
The Standard Way -
As I understand it your table looks like this:
SalesRep Customer PaidAmount
John Eric 2040
Stacy Brian 1020
Stacy Eric 2004
etc.
You will want to open up your table in Design view and add a column "CommRate"
so it will look like:
SalesRep Customer PaidAmount CommRate
John Eric 2040
Stacy Brian 1020
Stacy Eric 2004
etc.
The data type for CommRate should be Number - type Double - Now I would use Comm rate as a percentage - ie 10.2 = 10.2%, but you could also do .102 = 10.2% either one is fine (more on that later) save and close the table.
Now with the table selected use the create query wizard add all of the fields to the query, give the query a name and click modify the query at the end (or save it then open it up in design view). Now you will see each field in a column with the table listed below. Copy and paste the entry below to your query in one of the bank "field" locations:
for percentage ie 10.2=10.2%
Commission: [CommRate]*[PaidAmount]/100
for .102 = 10.2%
Commission: [CommRate]*[PaidAmount]
Now save and close the query.
Lastly you will select the query then click on create form. This will make a form based on the query. With this form you can add the CommRate individually and it will be saved for the future. You will see that when you add the CommRate the Commission field will automatically update and the table will get updated with the new value.
This is the standard way of doing this. Does this work for what you are doing?
Alright well that is good news! The primary key will help a lot:
Ok here is how you can solve this with two tables.
First create a new table with three columns:
"ID" - Primary Key "RelatedID" - Number Long Int "CommRate" - Number Double
This table will basically just be used to "add on" the CommRate without changing the linked table.
Next you will make a query that includes "SalesRep", "Customer" and "PaidAmount" from the linked table AND the "RelatedID" and "CommRate" from the new table.
When you view the query in design view you will see both tables above the list of the different fields and you will click on the primary key from the linked table and drag it to the "ReatedID" in the new table. From here it will open up a dialog asking about the relationship join. This part is the most important - You want to make the relationship a LEFT JOIN - You do this by saying you want to show ALL records from the Linked table and only the record from the New table that match. Basically this makes it so it will always show the records from the new table even if there is no entry that matches in the new table.
After you have that created you will just make a calculated field as before by copying:
Commission: [CommRate]*[PaidAmount]/100
to a new field on the query design
From here everything is set up and you can create a form based on the query you just made - I would delete the field "RelatedID" from the FORM (or the Query the relationship is what links it so its not necessary it is just a good double check) so you don't change it.
How it works - Now when you cycle through the entries you can add the commission rate directly to the form. - This will make a new entry in your new table that shows the primary ID of the transaction and the commission rate for that sale. This will update the calculated field and show you the commission. Then when you view it it will save the values individually without changing your original table.
Keep me posted if you need more help on how to do this. It can be a little tricky the first time you do it.

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.