microsoft access DLOOKUP with MAX function - ms-access

i have following table in access and i want that when the user click on the next record it should show the max value of digital_num based on the type for example:
when the form show the column type = "Petrol" another textbox that i added in the name of "text14" which has dlookup with max function it should show the value 200 in there not the 100 because i added max function.
ID Type Digital_Num
1 Petrol 100
2 Gas 50
3 Supper 150
4 Petrol 200
5 Gas 50
6 Supper 200
i added a textbox in the form in the name of "text14" besides the textboxes which automatically created for ID, Type, Digital_Num.
and i added the below Dlookup code to its control source
=DLookUp(Max("[Digital_Num]"),"table","[type] =" & '[Form].[type]')
when i switch my form to layout view it keeps showing 200 number in the text14 textbox which is the maximum value in the table it does not change even i press the next record
however it should show the max value of that type based when i click on the next record.

it may be more suitable to create an Aggregate Query to find the Max. Then do the LookUp of that query.
this is easier to test/debug then nesting the lookup and the max functionality in the same task

Related

Access Totals dynamically updated based on textboxes

All,
I run into some problems with totals using the DSUM function.
I have a Main form and a subform (details). The subform is displayed in datasheet view inside of the main form.
The subform contains a OppL_ID (PK, autonumber), Opp_ID (FK, is multiple times present), Product, Unit, Unit price.
Now I want to calculate the total revenue per Opp_ID on the main form. In the main form an Opp_ID selected, several rows with products are shown in the subform connected with that Opp_ID. If the user enters data in the datasheet view, the revenue must be calculated again directly.
I first try to get the formula working in the footer of the subform. But I cannot get the correct sum of revenue.
Now I have added in the query of the subform the Revenue: [Units]*[Unit Price]. This displays the revenue per unique line. I want the revenue per Opp_ID, so I tried the DSUM function.
What I tried:
To total the Revenue per Opp_ID I used the formula: DSUM([Units]*[Unit Price];"Qry_lines";"[Opp_ID]=" & [Opp_ID])
I also tried the control names instead: DSUM([txt_Units]*[txt_Unit Price];"Qry_lines";"[Opp_ID]=" & [Opp_ID])
I aslo tried to reference the Revenue field: DSUM([Revenue];"Qry_lines";"[Opp_ID]=" & [Opp_ID])
All of the formulas end in the result:
Example:
Opp_ID 51 consists of two lines with products A and B, Line of product A = Units 1 Unit price 20. Line of product B = Units 2 unit price 30.
Result: If I stand on A, the total revenue is 40 and on the line of product B 120.
I would expect only one figure:
1 * 20 + 2 * 30 = 80
It looks like it calculated revenue times the number of rows? What am I doing wrong?
I also tried to create a sum query and to reference this, for example:
Select Qry_lines.Opp_ID, Sum(Qry_lines.Revenue) as SumofRevenue FROM Qry_lines Group by Qry_lines.Opp_ID.
Now I get the correct figure per Opp_ID. Only I cannot reference this in my form? Perhaps with a Dlookup?
I think I am close but I cannot really nail it. Please help :)
Consider:
Use DLookup() domain aggregate function expression in textbox to reference the aggregate query.
Commit record edits to table with code in control's AfterUpdate event. One way is If Me.Dirty Then Me.Dirty = False
In same event, use Refresh or Requery or Recalc command on main form.

Calculated Textbox based on values from two fields in a form

I am having trouble trying to create an expression that will give me a total based on two values in two different text boxes.
I created a form that has a text box called Niin, textbox called variance, textbox called price and textbox called Total.
I also have a table called NIIN_PRICE that has a NIIN column and a price column next to the associated Niin.
The result i am seeking is:
Have the value entered in textbox Niin lookup the corresponding value in Table NIIN_PRICE WHICH will then output the price into the Price textbox.
I will then want the total textbox to be an expression by multiplying the value in variance textbox with the value in price textbox and get the total of both numbers.
Example:
I type 1234 in NIIN textbox in my form,
1234 is searched in the NIIN_PRICE table and returns the value of .25. .25 is added to the price textbox as an output.
i then type 4 in the variance textbox which will update my value in the total textbox to 1 (.25 from the price pull Multiplied by 4 from my variance input).
Is this request possible? Thank you for the help.
theForm might look like this>>
tbxNIIN tbxPrice tbxVariance tbxTotal
on tbxNIIN event tab add AfterUpdate sub
that reads the NIIN_PRICE table and copies the value to tbxPrice
and then clears tbxVariance and tbxTotal
and sets cursor to tbxVariance.
On tbxVariance event tab add AfterUpdate sub
that multiplies the two and puts the result in tbxTotal

Access 2013 Sum field column by ID number

My simple form
Here is my simple purchase order form.
The form based on 2 tables. One named POMaster (data being POID and PODate) and the other one named Items(data being What you see plus a type called POIDno which is linked to the POID field to store items by POID)
How do I get Text10 to equal the sum of ItemTotal Column (By POID ofcourse) and if possible How do I get this value to store in a (hopefully) new data field in POMaster I would name POTotal?
Put a hidden total text box on the sub form and set your text box to the value of the hidden control.
You shouldn't store the value in the header as it can always be calculated.
However if you are storing it, you would have to determine a specific point in your process and ideally make sure no more updates can be made to the order lines, as that would mean having to re-calculate your stored value.

How to set a Filter for the ComboBox List Items Edit Form?

Short form of the question:
How can I set a filter for the form which is used by the "List Items Edit Form" property of a ComboBox?
Long description of the environment:
In my database, there is a growing number of structurally similar values which describe something. I collated all of these in one table named ComboTexts, and added a second table ComboTextTypes to customize the field names on the user side. Example:
ComboTexts table:
ID s1 s2 s3 TypeID
1 1 First Floor Ground Floor 2
2 2 Second Floor Null 2
3 AOX DIN 1485 determination of organic components 3
ComboTextTypes table:
ID formtitle ch1 ch2 ch3
2 Floor Floor Number Floor Name Alternate Name
3 Process Process name Standard Description
In order to edit entries in ComboTexts, I provide two forms: The form CoreData displays the list of formtitles from ComboTextTypes and an "edit" button. When the user selects a fomtitle and clicks "edit", the form EditComboTexts is called with a filter for TypeID set. EditComboTexts extracts the TypeID from its filter and modifies itself with the information from ComboTextTypes.
So far there exist 14 ComboTextTypes in the database, and that number is growing. I simply didn't want to have 14 or more tables and forms, which basically all do the exact same thing. Instead I just have two tables and forms, although a little more complicated ones.
The above mechanic is all set up and works fine.
Description of the problem:
The users want to be able to modify the 14th ComboTextType from inside the combobox. The detour through CoreData is three clicks too many, they know that ComboBoxes can offer an edit button for their value list, and want to use it at that point.
Access offers the "List Items Edit Form" for this purpose. When I enter the EditComboTexts form there, it's working in principle, but (of course) the filter is wrong.
How can I set a filter for that form?
You can filter the rowsource using SQL and simply change the rowsource value of the combo box
Me.Combo0.RowSource = "SELECT myfield FROM Table2 WHERE Table2.myfilter = 'value' ; "

How to Autoexpand to a Duplicate Entry in a Combobox?

Salvete! I have an Access database (.accdb) with a combobox that will let me select records by typing into the box and pushing enter. Now, the list to which the combobox is bound has (of necessity) duplicates. What I want to do is to find a way to get the text of a duplicate item into the combobox. Problem is that AutoExpand only seems to see the first match.
I have a list with two columns, that looks like this:
Bob 20
Harry 5
Mike 45
Mike 46
Mike 78
Sherry 24
My code gets the index of what is displayed in the combobox, and then grabs the data from the second column.
How can I make Autoexpand display the second match (Mike, in this example)?
If you want the user (and the form) to distinguish between the 3 rows that say "Mike", you'll need to display both columns. Set your combobox to display both columns. Then, when the user types "M", the box will center on the first of the 3 rows with Mike.
One way this can be done is by changing your row source to "Select Name, Num from Tbl". Or just use the built-in wizard when making a new combobox.